Data Structures & AlgorithmsHardProduct Company SDE · stack round

Problem: Which structure supports push, pop and getting the minimum, all in O(1) amortised time?

  1. A. A plain queue
  2. B. A hash map alone
  3. C. A sorted array with binary search only
  4. D. A stack of (value, current minimum) pairs or a monotonic stack

Correct answer: D. A stack of (value, current minimum) pairs or a monotonic stack

Storing the running minimum with each stack entry keeps every operation constant time.

More Coding Interview Problems questions

Exams that ask this topic