Skip to content

Instantly share code, notes, and snippets.

@dkp1903
Created Jul 10, 2020
Embed
What would you like to do?
#define vector<int> vi;vi NGE(vi a){ stack<int>s; vi next(a.size()); int n = a.size(); for(int i = n-1; i >= 0; i--) { while(!s.empty() && s.top() <= a[i]) s.pop(); if(s.empty()) next[i] = -1; else next[i] = s.top();
s.push(a[i]); }
return next;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment