  InterviewBit Academy is now Scaler Academy! # Maximum product of an increasing subsequence of size 3

Problem Description

Given an array of integers A of size N.

Your task is to find maximum product of increasing subsequence of size 3

i.e. you need to find maximum value of A[i] * A[j] * A[k] such that A[i] < A[j] < A[k] and i < j < k < N for all increasing subsequences of size 3.

If there is no increasing subsequence of size 3 return -1, else return maximum product of increasing subsequence of size 3 modulo 109+7.

NOTE: All elements of the array A are distinct.

Problem Constraints

1 <= N <= 105

1 <= A[i] <= 106

Input Format

The only argument given is the integer array A.

Output Format

If there is no increasing subsequence of size 3 return -1, else return maximum product of increasing subsequence of size 3 modulo 109+7.

Example Input

Input 1:

``` A = [10, 11, 9, 5, 6, 1, 20]
```

Input 2:

``` A = [5, 4, 3, 2, 1]
```

Example Output

Output 1:

``` 2200
```

Output 2:

``` -1
```

Example Explanation

Explanation 1:

``` Maximum product is achieved when i=0, j=1, k=6 i.e A * A * A = 10 * 11 * 20 = 2200.
```

Explanation 2:

``` There is no increasing subsequence of size 3.
```

NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details. 