792. Next Greater Element
0
Medium
Given an array, print the Next Greater Element (NGE) for every element. The Next Greater Element for an element x is the first greater element on the right side of x in array. Elements for which no greater element exist, consider next greater element as -1.
Input Format
First line of the input contains a single integer T denoting the number of testcases.
First line of each testcase contains an integer N denoting the size of array.
Second line of each testcase contains N space seperated integers denoting the array.
Output Format
For each index, print its array element and its next greater element seperated by a comma in a new line.
Example
Input
2
4
11 13 21 3
5
11 9 13 21 3
Output
11,13
13,21
21,-1
3,-1
11,13
9,13
13,21
21,-1
3,-1
Constraints
1 <= T <= 50
1 <= N <= 10^5
Loading...
View Submissions
Console