Quant Memo
Coding/●●●●●

Design a queue that reports its minimum

A processing pipeline holds quotes in arrival order: new quotes join the back, the oldest are served from the front, and at any moment you need the smallest quote still in flight. That is a min-queue: enqueue, dequeue (FIFO), and get_min, all in amortized O(1)O(1).

q = MinQueue()
q.enqueue(5); q.enqueue(3); q.enqueue(7)
q.get_min() -> 3
q.dequeue() -> 5        # FIFO: oldest leaves first
q.get_min() -> 3        # 3 and 7 remain

A min-stack is not enough on its own, a queue removes from the opposite end. The classic build is two min-stacks.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions