946. Validate Stack Sequences
class Solution { public: bool validateStackSequences(vector<int>& pushed, vector<int>& popped) { stack<int> sta; int index = 0; for(int i = 0;i < pushed.size();i++){ sta.push(pushed[i]); while(!sta.empty() && sta.top() == popped[index]){ sta.pop(); index++; } } return index == popped.size(); } };