Find The Next Larger Element

easy
1. Given an array A of size N having distinct elements.
  2. Find the next greater element for each element of the array in order of their appearance in the array.
  3. If no such element exists, output -1.

Input Format

First line contains 'N'(size of the array) Second line contains N nmuber of integer elements.

Output Format

Print N number of elements for each element in the given array.

Constraints

1 <= N <= 107
  1 <= Ai < 10^9

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
4
1 3 2 4
Output
3
4
4
-1
Previous
Finding Negative Value In Ksize Window
Next
Lets Make A Queue Using Array

Related Questions