You are viewing a single comment's thread. Return to all comments →
A very easy solution in c++
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; stack<int> s; stack<int> maxStack; while(n--){ int a,b; cin>>a; if(a==1){ cin>>b; } if(a==1){ s.push(b); if(maxStack.empty()){ maxStack.push(b); } else{ maxStack.push(max(maxStack.top(),b)); } } else if(a==2){ s.pop(); maxStack.pop(); } else{ cout<<maxStack.top()<<endl; } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Element
You are viewing a single comment's thread. Return to all comments →
A very easy solution in c++