Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: A stack of plates is filled by pushing 1 to 6 in order and popping after each push whenever the top is even. The final stack, read from bottom to top, is what?

  1. A. [1, 3, 4]
  2. B. [2, 4, 6]
  3. C. [1, 3, 5]
  4. D. [1, 3, 5, 6]

Correct answer: C. [1, 3, 5]

Simulate the push and conditional pop exactly. Popping before pushing changes which values remain on the stack.

More Coding Interview Problems questions

Exams that ask this topic