Next Greater in Stack

For each element in the array, find the next greater element using a stack.

Input Format

Integer n
n space-separated integers

Output Format

n space-separated integers (next greater or -1)

Sample Input

4
4 5 2 10

Sample Output

5 10 10 -1

Try Your Code

← Back to Problems List