1class Solution {2public:3bool validateStackSequences(vector<int> &pushed, vector<int> &popped) {4stack<int> st; // Create a stack56int j = 0; // Intialise one pointer pointing on popped array78for (auto val : pushed) {9st.push(val); // insert the values in stack10while (st.size() > 0 && st.top() == popped[j]) { // if st.peek() values equal to popped[j];11st.pop(); // then pop out12j++; // increment j13}14}15return st.size() == 0; // check if stack is empty return true else false16}17};