Stacks and Queues
Used to maintain temporal or order-based state. Common in parsing, monotonic operations, and backtracking patterns.
1.0 Stack Fundamentals
- LIFO principle and implementation via arrays or LL
- Expression parsing and evaluation
- Reversing structures
2.0 Validity Checking Patterns
- Valid parentheses/brackets
- Minimum add to make valid
- Remove invalid parentheses (generate all)
3.0 Monotonic Stack Patterns
- Next greater/smaller element
- Nearest smaller to left/right
- Histogram problems (max rectangle area)
4.0 Min/Max Stack Variants
- Stack with min in O(1)
- Design stack with constant-time retrievals
- Max Stack or Stack of Stacks
5.0 Backtracking and Undo Stack
- Evaluate Reverse Polish Notation
- Path simplification (
../,./) - Browser-like undo/redo patterns
6.0 Queue Fundamentals
- FIFO queue basics and circular queue
- Implementation with 2 stacks
- Multi-producer consumer simulation
7.0 Monotonic Queue & Sliding Window
- Sliding window max/min
- 1D DP optimizations with queue (jump game, rotten oranges)
- Using deque for state preservation
8.0 Design Problems with Queue
- Implement Stack using Queue
- Implement Queue using Stack
- LRU cache with deque
- Moving average / time-based hit counter
9.0 Priority Queue (Heap-backed)
- Top K elements
- Merge K sorted streams
- Frequency sorting
- Custom comparators
10.0 Special Mentions
- Stack of stacks
- Balanced binary expression evaluator
- Largest rectangle in histogram
- Implement circular deque
- Wait time problems (stock span, daily temps)