π Stack
Stacks shine when you need to "remember the last thing" β matching brackets, evaluating expressions, finding the next greater element. The monotonic stack is the highest-leverage pattern here.
This category contains 9 problems. Use the patterns below to recognize what's being asked, then jump to the problem list at the bottom.
π§ Key Patternsβ
- Bracket Matching / Validation β Push opens, pop & compare on close.
- Monotonic Stack β Next greater/smaller element. amortized.
- Expression Evaluation β Shunting yard, postfix evaluation.
- Min/Max Stack β Auxiliary stack tracking running min/max.
- Simulating Recursion β Iterative DFS, in-order without recursion.
β οΈ Common Pitfallsβ
- Forgetting to flush remaining elements after the main loop (e.g. unmatched brackets).
- Monotonic stack: choosing wrong comparison direction.
π Study Resourcesβ
πΊ Videosβ
π Booksβ
- Algorithms β Sedgewick β Ch. 1.3
π Articles & Referencesβ
π» All Stack Problemsβ
Asteroid Collision
LeetCode 735 | Difficulty: Medium
Baseball Game
LeetCode 682 | Difficulty: Easy
Basic Calculator
LeetCode 224 | Difficulty: Hard
Basic Calculator II
LeetCode 227 | Difficulty: Medium
Basic Calculator III
LeetCode Link
Crawler Log Folder
LeetCode 1720 | Difficulty: Easy
Next Greater Element I
LeetCode 496 | Difficulty: Easy
Next Greater Element II
LeetCode 503 | Difficulty: Medium
Next Greater Element III
LeetCode 556 | Difficulty: Medium