Data Structures & AlgorithmsModerateGATE CS · TCS NQT

A stack starts empty. The operations are ['push', 'push', 'pop', 'push', 'push', 'pop', 'push', 'push', 'push', 'pop', 'push']. How many times does the stack height reach a NEW maximum (a height strictly greater than every height reached before)?

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

Correct answer: C. 5

Track the running height and the best height so far, and count each push that makes a new record. Counting pushes overall, or counting heights above zero, measures something else.

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

Exams that ask this topic