Pattern Recognition Drill
Medium Intervals
The Problem
Given a sorted list of non-overlapping intervals and a new interval, insert and merge if necessary.
What approach would you use?
Think about it before scrolling down.
Add all before, merge overlapping ones, add all after. O(n).
Find insertion point with bisect, then merge. O(n) due to shifting.
Common Trap
Don't re-sort the entire list — it's already sorted. A single linear pass suffices.