Data Structures & AlgorithmsHardProduct Company SDE · data structures

Problem: Which structure gives a queue with O(1) amortised enqueue, dequeue and minimum queries?

  1. A. A binary search tree with rebalancing only
  2. B. Two stacks with running minima, or a monotonic deque
  3. C. A hash table
  4. D. A linked list alone

Correct answer: B. Two stacks with running minima, or a monotonic deque

Two stacks each store running minima, so the queue minimum is the smaller of the two stack tops.

More Coding Interview Problems questions

Exams that ask this topic