Consider an empty stack. What will the stack look like (starting from the top) after executing the following operations in sequence?
- push(7)
- push(5)
- push(9)
- push(11)
- pop()
- push (22)
(A) 22
(B) 9
(C) 5
(D) 7
Consider an empty stack. What will the stack look like (starting from the top) after executing the following operations in sequence?
- push(7)
- push(5)
- push(9)
- push(11)
- pop()
- 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.
| Operation | Stack (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.
Related questions:
2025: 13 May Shift 2
2025: 27 May Shift 2
2026: 26 May Shift 1
2025: 15 May Shift 2