Suppose there are 3 elements 4, 2 and 7 to be input in the same order in the stack. In what sequence should the operation follow, so the final content of the stack from top to bottom is [7,4]?
(A) PUSH[4]
(B) POP
(C) PUSH[2]
(D) PUSH[7]
Suppose there are 3 elements 4, 2 and 7 to be input in the same order in the stack. In what sequence should the operation follow, so the final content of the stack from top to bottom is [7,4]?
(A) PUSH[4]
(B) POP
(C) PUSH[2]
(D) PUSH[7]
Solution
✅ Correct Option: 4
Elements go in the order 4, 2, 7, and a stack removes the most recent element first. To end with 7 on top of 4, the element 2 must be pushed and then popped before 7 is pushed.
| Operation | Stack (top to bottom) |
|---|---|
| (A) PUSH[4] | 4 |
| (C) PUSH[2] | 2, 4 |
| (B) POP | 4 |
| (D) PUSH[7] | 7, 4 |
Option 1: the POP removes 4, not 2, leaving [7, 2].
Option 2: the POP removes 4, and 2 is pushed last, giving [2, 7].
Option 3: starting with POP on an empty stack causes underflow.
Related questions:
2026: 26 May Shift 1
2026: 24 May Shift 1
2026: 29 May Shift 1
2025: 20 May Shift 1