← All problems

Min Stack

Medium stacksdesign LeetCode ↗
Design a stack that supports push, pop, top, and retrieving the minimum element, all in O(1) time. The challenge is getMin: think about what auxiliary information must be maintained on each push.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(1) all ops, Space O(n)

Common pitfalls

  • Popping the min tracking on duplicate mins
  • Recomputing min on pop (O(n))

Your solution

Log in to save your code and track progress.