So I am following this algorithm course from Princeton University done through coursera. I was doing this question related to stacks. The answer baffles me. Appreciate if anyone can kindly show me where I am going wrong in this;
Question : Suppose that an intermixed sequence of push and pop operations are performed on a LIFO stack. The pushes push the letters A through J in order; the pops print out the return value. Which of the following output sequence(s) could occur?
Correct answer 1 : B E D C G A F I J H
Explanation : When G is pushed, both A and F are still on the stack. So, F would be popped before A.
My question : If F should appear before A, then that answer cannot be true right?
Correct answer 2 : B C E A I J H G F D
Explanation : When E is pushed, both A and D are still on the stack. So, D would be popped before A.
My Question : again D should come before A right?
Appreciate if someone can show me what I might be doing wrong.