Mid
Stacks / Design
DSA & Coding Interviews
Explain Min Stack design.
Short answer: Keep a normal stack plus an auxiliary stack of current minima (or store pairs). push/pop/top/getMin all O(1). On push, push min(x, currentMin) onto the min stack.
Complexity
All operations O(1), Space O(n).
Do not scan the stack for getMin — that is O(n) and fails the prompt.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png