Consider the following operations performed on a stack of size 5.
PUSH(17), POP(), PUSH(12), PUSH(13), POP(), PUSH(41), POP(), POP(), PUSH(54)
After the completion of all operations , the number of elements present in the stack are:
Consider the following operations performed on a stack of size 5.
PUSH(17), POP(), PUSH(12), PUSH(13), POP(), PUSH(41), POP(), POP(), PUSH(54)
After the completion of all operations , the number of elements present in the stack are:
Solution
✅ Correct Option: 1
Each PUSH adds one element and each POP removes one. The stack never goes below empty and never exceeds size 5, so every operation succeeds.
| Operation | Stack after (bottom to top) |
|---|---|
| PUSH(17) | 17 |
| POP() | empty |
| PUSH(12) | 12 |
| PUSH(13) | 12, 13 |
| POP() | 12 |
| PUSH(41) | 12, 41 |
| POP() | 12 |
| POP() | empty |
| PUSH(54) | 54 |
Quick method: 5 PUSH operations and 4 POP operations give element.
Related questions:
2026: 23 May Shift 1
2026: 29 May Shift 2
2026: 23 May Shift 2
2026: 20 May Shift 1
2026: 11 May Shift 2
2026: 26 May Shift 1