**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 **10 ^{9}+7**.

**NOTE:** All elements of the array A are distinct.

1 <= N <= 10^{5}

1 <= A[i] <= 10^{6}

The only argument given is the integer array **A**.

If there is no increasing subsequence of size 3 return **-1**, else return maximum product of increasing subsequence of size 3 modulo **10 ^{9}+7**.

Input 1:

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

Input 2:

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

Output 1:

2200

Output 2:

-1

Explanation 1:

Maximum product is achieved when i=0, j=1, k=6 i.e A[0] * A[1] * A[6] = 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.

Sign Up

to access hints and editorial solutions for**Maximum product of an increasing subsequence of size 3**

to access hints and editorial solutions for

Loading...