Next Greater

3.7

3 votes
Easy
Problem

Given an array, print the Next Greater Element 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

First line contains one integer N denoting the size of array.

Second line contains N integers.
OUTPUT

Output N integers each denoting the Next greater element in the array.
CONSTRAINTS

1N105

1Ai106

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?