Next Geater Element

 

Given an array, print the Next Greater Element (NGE) for every element. The Next greater Element for an element x, is the first greater element on right side of x in the array. Elements for which no greater element exist, consider next greater element as -1.

Input format :

Line 1 : Size of input array

Line 2 : Array elements (separated by space)

Constraints:
Time Limit: 1 second
Size of input array lies in the range: [1, 1000000]
Sample Input
5
3  8  1  2  0
Sample Output
8 -1  2 -1 -1


#include <vector>
#include<bits/stdc++.h>

vector<int> nextGreaterElement(vector<int> input) {
// Write your code here

vector<int>ans;
stack<int>st;
for(int i=input.size()-1;i>=0;i--){
if(st.empty())
}

}

Comments

Popular posts from this blog

Code : All connected components

Coding Ninjas

Code : Get Path - BFS