Skip to content

Instantly share code, notes, and snippets.

@dkp1903
Created July 10, 2020 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkp1903/b92acc8e53c6c83234b41f32072c6560 to your computer and use it in GitHub Desktop.
Save dkp1903/b92acc8e53c6c83234b41f32072c6560 to your computer and use it in GitHub Desktop.
#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