MAXSPPROD

You are given an array A containing N integers. The special product of each ith integer in this array is defined as the product of the following:<ul>

  • LeftSpecialValue: For an index i, it is defined as the index j such that A[j]>A[i] (i>j). If multiple A[j]’s are present in multiple positions, the LeftSpecialValue is the maximum value of j.

  • RightSpecialValue: For an index i, it is defined as the index j such that A[j]>A[i] (j>i). If multiple A[j]s are present in multiple positions, the RightSpecialValue is the minimum value of j.

    Write a program to find the maximum special product of any integer in the array.

    Input: You will receive array of integers as argument to function.

    Return: Maximum special product of any integer in the array modulo 1000000007.

    Note: If j does not exist, the LeftSpecialValue and RightSpecialValue are considered to be 0.

    Constraints 1 <= N <= 10^5 1 <= A[i] <= 10^9

  • 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.
    Start solving MAXSPPROD on Interview Code Editor
    Sign Up
    to access hints and editorial solutions for MAXSPPROD

    Discussion


    Loading...
    Click here to start solving coding interview questions