Next Greater to the Right
For every element print the first strictly greater element to its right, or −1 if none exists.
Input: the first line has N; the second line has N integers.
Output: N integers: the next greater element of each position.
Constraints:
- 1 ≤ N ≤ 105
- −109 ≤ ai ≤ 109
Sample Tests
Input 1
4 2 1 2 4
Output 1
4 2 4 -1
Input 2
3 3 2 1
Output 2
-1 -1 -1
Discussion (opens after you solve — no spoilers before)
No comments yet.