26 worked problems

Stack

LIFO bookkeeping for matching and order. The most recent unresolved item must be handled first, or you need the next greater or smaller boundary.

Recognition signal

When should you think of Stack?

The most recent unresolved item must be handled first, or you need the next greater or smaller boundary.

Core invariant

What must stay true?

The stack contains unresolved items in the exact order or monotonic shape required.

Practice in a deliberate order

What to learn in this cluster

  1. 01Matching and parsing
  2. 02Monotonic stacks
  3. 03Expression and state simulation

All Stack problems

26 of 26 walkthroughs
Continue the cluster

Related patterns and study guides