Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

Process [3, 1, 4, 1, 5, 9, 2, 6] with a stack: before pushing each value, pop while the top is smaller than it. How many pop operations happen in total?

  1. A. 6
  2. B. 7
  3. C. 8
  4. D. 10

Correct answer: A. 6

Count each time a larger value evicts a smaller top; equal values are not popped under the 'strictly smaller' rule.

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

Exams that ask this topic