week 5 of 15
Stacks and queues
Get comfortable with these coding mechanics first: stack push, pop and peek. Queue or deque operations. Storing indexes or tuples on a stack. Template to type from memory by the end of the week: monotonic stack: for each element, while the stack top is worse, pop and settle it. Then push.
- 40Valid Parentheses (opens LeetCode in a new tab)Stack matchingEasy
- Common mistake
- Popping from an empty stack.
- 41Min Stack (opens LeetCode in a new tab)Stack with an auxiliary minimumMedium
- Common mistake
- Forgetting that the min must be removed together with the value.
- 42Evaluate Reverse Polish Notation (opens LeetCode in a new tab)Expression stackMedium
- Common mistake
- Operand order for - and /. Division truncates toward zero.
- 43Daily Temperatures (opens LeetCode in a new tab)Monotonic stackMedium
- Common mistake
- Storing values instead of indexes.
- 44Car Fleet (opens LeetCode in a new tab)Sort + monotonic stackMedium
- Common mistake
- Sorting positions without keeping each speed paired with its position.
- 45Asteroid Collision (opens LeetCode in a new tab)Stack simulationMedium
- Common mistake
- Handling all three outcomes (top wins, new wins, both die).
- 46Largest Rectangle in Histogram (opens LeetCode in a new tab)Monotonic stack (hard)Hard
- Common mistake
- Getting the width calculation wrong, and forgetting the final flush.
- 47Sliding Window Maximum (opens LeetCode in a new tab)Monotonic dequeHard
- Common mistake
- Storing values instead of indexes, so you cannot expire the front.