Next Greater Element
View as PDFYou are given an array of integers.
For each position , find the first element to the right of
that is strictly greater than
. If no such element exists, output
-1 for that position.
Input
The first line contains an integer , the size of the array.
The second line contains integers:
.
Output
Print integers, where the
-th integer is the next greater element to the right of
,
or
-1 if none exists.
Constraints
Example 1
Input
5
4 5 2 10 8
Output
5 10 10 -1 -1
Example 2
Input
4
13 7 6 12
Output
-1 12 12 -1
Example 3
Input
4
3 3 3 3
Output
-1 -1 -1 -1
Comments