Skip to main contentSkip to solution

The following operations are performed on an empty stack:

push(10) push(20) push(30) pop() push(46) pop() pop() push (34) push(12) pop() push(16) push(4)

Which of the following elements will be present on the stack?

A. 16

B. 10

C. 4

D. 34

Solution

✅ Correct Option: 3

A pop removes the most recently pushed element (last in, first out). Stack contents are shown from bottom to top.

OperationStack
push(10)10
push(20)10, 20
push(30)10, 20, 30
pop() removes 3010, 20
push(46)10, 20, 46
pop() removes 4610, 20
pop() removes 2010
push(34)10, 34
push(12)10, 34, 12
pop() removes 1210, 34
push(16)10, 34, 16
push(4)10, 34, 16, 4

The final stack holds 10, 34, 16 and 4, so all of A, B, C and D are present.

Keyboard Shortcuts

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