import java.util.*;

public class Solution {
    public boolean IsPopOrder(int [] pushA,int [] popA) {
      Stack<Integer> st = new Stack<>();

      int index = 0;
      for(int i = 0; i < pushA.length; ++i){
          st.push(pushA[i]);
          while(!st.isEmpty() && index <= popA.length && st.peek() == popA[index]){
              st.pop();
              index++;
          }
      }

      return st.isEmpty();
    }
}