Problem of the day
Input: [1,2,1]
Output: 2 -1 2
The first greater element next to 1 is 2.
There is no greater element next to 2 while traversing circularly, hence answer is -1.
The first greater element next to 1 is 2.
The first line will contain the integer 'T', denoting the number of test cases.
The first line of each test case contains one integer 'N' denoting the size of array 'A'.
The second line of each test case contains 'N' single space-separated integers, elements of the array 'A'.
For each test case, Return the Next Greater Element(NGE) for every element.
.
You don't need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^5
0 <= A[i] <= 10ٰ^9
Time Limit: 1 sec
2
3
1 2 1
5
1 2 3 4 3
##### Sample Output 1 :
2 -1 2
2 3 4 -1 4
For the first case:
Input: [1,2,1]
Output: 2 -1 2
The first greater element next to 1 is 2(index 2).
There is no greater element next to 2 while traversing circularly, hence answer is -1.
The first greater element next to 1 is 2(index 2).
For the second case:
Input: [1,2,3,4,3]
Output: 2 3 4 -1 4
The first greater element next to 1 is 2(index 2).
The first greater element next to 2 is 3(index 3).
The first greater element next to 3 is 4(index 4).
There is no greater element next to 4 while traversing circularly, hence answer is -1.
The first greater element next to 3 is 4(index 3).
2
8
6 1 50 1 50 30 6 100
6
55 19 21 13 10 67
50 50 100 50 100 100 100 -1
67 21 67 67 67 -1