We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
vector<int>getMax(vector<string>operations){vector<int>ans;intMax=INT_MIN;stack<int>st;intn=operations.size();for(inti=0;i<n;i++){strings=operations[i];intopern=stoi(s.substr(0,1));//perform operationsif(opern==1){//push operationintval=stoi(s.substr(2));if(val>=Max){st.push(Max);Max=val;}st.push(val);}elseif(opern==2){// pop operationif(Max==st.top()){st.pop();Max=st.top();}st.pop();}elseif(opern==3){ans.push_back(Max);}}returnans;}
Cookie support is required to access HackerRank
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 →