Maximum Index
Submissions: 50824   Accuracy:

31.25%

  Difficulty: Medium   Marks: 4
Associated Course(s):   Interview Preparation
     

Given an array A of positive integers. The task is to find the maximum of j - i subjected to the constraint of A[i] <= A[j].

Input:
The first line contains an integer T, depicting total number of test cases.  Then following T lines contains an integer N depicting the size of array and next line followed by the value of array.

Output:
Print the maximum difference of the indexes i and j in a separtate line.

Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 107
0 ≤ A[i] ≤ 1018

Example:
Input:
1
9
34 8 10 3 2 80 30 33 1

Output:
6

Explanation:
Testcase 1: 
In the given array A[1] < A[7] satisfying the required condition(A[i] <= A[j]) thus giving the maximum difference of j - i which is 6(7-1).

** For More Input/Output Examples Use 'Expected Output' option **

Author: shef5


Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.