Stack / Queue
Stacks (last-in-first-out) and queues (first-in-first-out) control the order in which work is processed. Use a stack for nesting, matching, and undo-style backtracking; use a queue for level-by-level or first-come-first-served processing.
12 LeetCode problems solved with the Stack / Queue pattern. Practice them with spaced repetition so the pattern sticks.
- Asteroid CollisionMEDIUM · O(n)
- Baseball GameEASY · O(n)
- Basic CalculatorHARD · O(n)
- Decode StringMEDIUM · O(n)
- Evaluate Reverse Polish NotationMEDIUM · O(n)
- Longest Valid ParenthesesHARD · O(n)
- Min StackMEDIUM · O(1)
- Number of Recent CallsEASY · O(1)
- Remove All Adjacent Duplicates In StringEASY · O(n)
- Removing Stars From a StringMEDIUM · O(n)
- Simplify PathMEDIUM · O(n)
- Valid ParenthesesEASY · O(n)
See the full solution
The complete approach, reference solutions in 5 languages, and a step-by-step visualization — then add this problem to your spaced-repetition schedule.
Start free →