Data Structures & AlgorithmsHardTCS NQT · Infosys

Push and pop operations on an initially empty stack are: push, push, pop, push, push, push, pop, pop, push. What is the maximum height the stack ever reaches?

  1. A. 4
  2. B. 5
  3. C. 6
  4. D. 8

Correct answer: A. 4

The height goes 1, 2, 1, 2, 3, 4, 3, 2, 3, so the peak is 4. The final height 3 is not the maximum.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic