Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: Starting with the stack [1] (top is the rightmost element), the operations are: push 2, push 3, pop, push 4, push 5, pop, pop. What is the top element at the end?

  1. A. 3
  2. B. 1
  3. C. 2
  4. D. 4

Correct answer: C. 2

Simulate each push and pop in order and read the final top. Mistaking the stack for a queue gives a different element.

More Coding Interview Problems questions

Exams that ask this topic