vector<int> nextLargerElement(vector<int>& arr) {
// code here
int n = arr.size();
vector<int> ans(n, -1);
stack<int> st;
for(int i=n-1; i>=0; i--) {
while(!st.empty() && arr[i] >= st.top()) st.pop();
if(!st.empty()) ans[i] = st.top();
st.push(arr[i]);
}
return ans;
}
GFG PTOD | 23 Feb | Next Greater Element | Medium level | STACK – Learn to Code and Code to Learn
reebjnhzey http://www.g60i4pva91x12rs81w8h22n92nhvp11rs.org/
areebjnhzey
[url=http://www.g60i4pva91x12rs81w8h22n92nhvp11rs.org/]ureebjnhzey[/url]