Consider the given stack with 6 elements at the beginning as shown below:
2 5 7 3 1 13
If the following operations are performed in order
push(10), pop(), push(15), pop(), push(35), pop(), pop() , pop(), pop()
Specify the order of elements in which they are popped in last four pop() operations.
A. 3
B. 1
C. 13
D. 35
Consider the given stack with 6 elements at the beginning as shown below:
| 2 | 5 | 7 | 3 | 1 | 13 |
|---|
If the following operations are performed in order
push(10), pop(), push(15), pop(), push(35), pop(), pop() , pop(), pop()
Specify the order of elements in which they are popped in last four pop() operations.
A. 3
B. 1
C. 13
D. 35
Solution
The last element, 13, is at the top of the stack. Each push(x) is immediately followed by a pop() that removes x, so 10, 15 and 35 are popped in turn and the stack returns to its original state.
The last four pop() operations are 35 (from the push(35) pair), then the original elements from the top: 13, 1, 3.
The popped order is 35, 13, 1, 3, which is D, C, B, A.
Related questions:
2026: 20 May Shift 1
2025: 16 May Shift 1