week 9 of 15
Intervals and greedy
Get comfortable with these coding mechanics first: sorting by a key, comparing with the last element of a result list, tracking a running max or min. Template to type from memory by the end of the week: sort by the right key, then one pass keeping a few variables.
- 75Merge Intervals (opens LeetCode in a new tab)Sort by start, mergeMedium
- Common mistake
- Using < (touching intervals should merge) and forgetting max.
- 76Insert Interval (opens LeetCode in a new tab)Three phasesMedium
- Common mistake
- Getting the overlap test wrong.
- 77Non-overlapping Intervals (opens LeetCode in a new tab)Greedy by end timeMedium
- Common mistake
- Sorting by start instead of end.
- 78Jump Game (opens LeetCode in a new tab)Greedy farthest reachMedium
- Common mistake
- Getting the loop bound wrong, or not checking i > farthest first.
- 79Jump Game II (opens LeetCode in a new tab)Greedy windowMedium
- Common mistake
- Counting one jump too many at the last index.
- 80Gas Station (opens LeetCode in a new tab)One pass with a running tankMedium
- Common mistake
- Not understanding why the reset works. Do a small example by hand.
- 81Partition Labels (opens LeetCode in a new tab)Greedy by last occurrenceMedium
- Common mistake
- Forgetting to reset start.
- 82Valid Parenthesis String (opens LeetCode in a new tab)Track a range of open countsMedium
- Common mistake
- Forgetting to clamp lo at 0.
- 83Candy (opens LeetCode in a new tab)Two passesHard
- Common mistake
- Using assignment instead of max in the second pass.