import java.util.LinkedList;

public class Solution {
    public boolean IsPopOrder(int [] pushA,int [] popA) {
        LinkedList<Integer> stack = new LinkedList<Integer>();
        for(int pushIdx = 0, popIdx = 0; pushIdx < pushA.length; pushIdx++) {
            stack.addLast(pushA[pushIdx]);
            while((stack.size() > 0)
                  && (popIdx < popA.length) 
                  && (stack.getLast() == popA[popIdx])) {
                popIdx++;
                stack.removeLast();
            }
        }
        return stack.size() == 0;
    }
}