Skip to main contentSkip to solution

Consider an empty stack. What will the stack look like (starting from the top) after executing the following operations in sequence?

  1. push(7)
  2. push(5)
  3. push(9)
  4. push(11)
  5. pop()
  6. push (22)

(A) 22

(B) 9

(C) 5

(D) 7

Solution

✅ Correct Option: 1

A stack follows Last In, First Out, so pop() removes the most recently pushed item.

OperationStack (top first)
push(7)7
push(5)5, 7
push(9)9, 5, 7
push(11)11, 9, 5, 7
pop()9, 5, 7
push(22)22, 9, 5, 7

From the top, the stack is 22, 9, 5, 7, which is (A), (B), (C), (D).


Option 2: lists the stack from bottom to top, but the question asks for top first.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question