1class Solution {2public boolean validateStackSequences(int[] pushed, int[] popped) {3Stack<Integer> st = new Stack<>(); // Create a stack45int j = 0; // Intialise one pointer pointing on popped array67for (int val : pushed) {8st.push(val); // insert the values in stack9while (!st.isEmpty() && st.peek() == popped[j]) { // if st.peek() values equal to popped[j];10st.pop(); // then pop out11j++; // increment j12}13}14return st.isEmpty(); // check if stack is empty return true else false15}16}