class Solution {
public boolean validateStackSequences(int[] pushed, int[] popped) {
Stack<Integer> stk1=new Stack<>();
int l=0,r=0;
for(int i=0;i<pushed.length;i++){
stk1.push(pushed[i]);
while(!stk1.empty()&&stk1.peek()==popped[r]){
stk1.pop();
r++;
}
}
return stk1.empty();
}
}