Problem editorialeasy
Design a min stack
Push and pop in O(1) is free. The trick is answering “what is the minimum right now?” instantly — without ever scanning.
16 min read·time O(1) per op·space O(N)
Auxiliary stackInvariant designO(1) queries
Push and pop in O(1) is free. The trick is answering “what is the minimum right now?” instantly — without ever scanning.