knaxuslearn · build · ship

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.

  1. 75Merge Intervals (opens LeetCode in a new tab)Sort by start, mergeMedium
    Common mistake
    Using < (touching intervals should merge) and forgetting max.
  2. 76Insert Interval (opens LeetCode in a new tab)Three phasesMediumcore
    Common mistake
    Getting the overlap test wrong.
  3. 77Non-overlapping Intervals (opens LeetCode in a new tab)Greedy by end timeMediumcore
    Common mistake
    Sorting by start instead of end.
  4. 78Jump Game (opens LeetCode in a new tab)Greedy farthest reachMediumcore
    Common mistake
    Getting the loop bound wrong, or not checking i > farthest first.
  5. 79Jump Game II (opens LeetCode in a new tab)Greedy windowMedium
    Common mistake
    Counting one jump too many at the last index.
  6. 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.
  7. 81Partition Labels (opens LeetCode in a new tab)Greedy by last occurrenceMedium
    Common mistake
    Forgetting to reset start.
  8. 82Valid Parenthesis String (opens LeetCode in a new tab)Track a range of open countsMedium
    Common mistake
    Forgetting to clamp lo at 0.
  9. 83Candy (opens LeetCode in a new tab)Two passesHard
    Common mistake
    Using assignment instead of max in the second pass.