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')
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.
| Operation | Stack (bottom to top) |
|---|---|
| append('C') | C |
| append('O') | C O |
| append('M') | C O M |
| pop() removes M | C O |
| append('U') | C O U |
| append('R') | C O U R |
| pop() removes R | C 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.
Related questions:
2025: 3 June Shift 2
2025: 21 May Shift 1
2025: 13 May Shift 2
2025: 15 May Shift 2