Stack
Use LIFO ordering to match pairs, track state, or maintain monotonic sequences for next-greater/smaller element problems.
- • Matching parentheses/brackets
- • Next greater/smaller element
- • Expression evaluation
- • Monotonic relationships
- • Need random access
- • Need FIFO ordering (use queue)
- • Empty stack access
- • Not handling the remaining elements after iteration
- • Confusing push/pop order
Key Invariant
The stack maintains elements in a useful order — monotonic stacks keep elements sorted for O(n) lookups