Stack problems, grouped by pattern
A stack remembers the most recent thing you have not dealt with yet. That makes it the natural tool for matching brackets, undoing operations, simulating collisions and evaluating expressions.
When to reach for it
- Something opens and must later be closed
- The latest item decides what happens next
- You need to evaluate or parse an expression
Mistakes to watch for
- Popping from an empty stack
- Leaving unmatched items on the stack at the end
- Mixing operand order for subtraction and division
The 7 problems
1Stack Basics
- Valid Parentheses Animated Easy
- Baseball Game Animated Easy
- Asteroid Collision Animated Medium
- Min Stack Animated Medium
- Remove All Adjacent Duplicates In String Animated Easy
- Evaluate Reverse Polish Notation Animated Medium
- Basic Calculator Animated Hard