Skip to main contentSkip to solution

Given various operations to be performed on stack, find the output:

stack=[ ]

stack.append('C')

stack.append('O')

stack.append('M')

stack.pop()

stack.append('U')

stack.append('R')

stack.pop()

stack.append('N')

stack.append('T')

Solution

✅ Correct Option: 2

A stack is last-in, first-out: append adds to the top and pop() removes the top item.

OperationStack (bottom to top)
append('C')C
append('O')C O
append('M')C O M
pop() removes MC O
append('U')C O U
append('R')C O U R
pop() removes RC O U
append('N')C O U N
append('T')C O U N T

Option 3: lists every pushed letter and ignores that the two pop() calls removed M and R.

Option 4: only the last two pushes, but earlier items stay on the stack unless popped.

Keyboard Shortcuts

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