Skip to main contentSkip to solution

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.

OperationStack 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 5−4=15 - 4 = \boxed{1} element.

Keyboard Shortcuts

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