← Stack

Pattern Recognition Drill

#18 — Min stack

Medium Stacks & Queues

The Problem

Design a stack that supports push, pop, and getMin in O(1).

What approach would you use?

Think about it before scrolling down.

Key Signals

Stack

Store (value, current_min) pairs. On push, new_min = min(val, top.min). O(1) for all operations.

Common Trap

Tracking a single min variable breaks on pop — you lose the previous minimum.

← #17 #19 →