Indexing

3.5

2 votes
Problem

Given an array of n integers you have to find a pair of indices (i,j) such that i<j and value at index, i is less than or equal to the value at index j i.e (A[i]<=A[j]).

Among all such possible pair, you have to find the pair of indices which give the maximum possible value of difference j-i.


INPUT: The first line of the input contains the number of test cases T, the first line of each test case contains an integer N denoting the size of the array, and the next line contains N space separated integers, the elements of the array.

OUTPUT: Output a single line containing the maximum possible value as asked in the question. If no such pair exists print "-1".

CONSTRAINTS:

1 < T < 1000

< N < 103.

< A[i] < 1018.

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?