Scanning & Windows
Interval Problems
When you see it
Signal words
If the prompt uses any of these, this pattern should come to mind first.
intervalsoverlapmergemeeting roomsschedulestart / end times
Practice
Drill this pattern with an AI trainer — reply only with Hint, Next, Lost, or paste your code.
Ask yourself
- Inputs are
[start, end]ranges? - Merge, count overlaps, or insert into a schedule?
- Sort by start (or by end for greedy selection).
Classic problem
Merge Intervals (LeetCode 56) — merge all overlapping intervals. Sort by start, then extend the last kept interval whenever the next one overlaps it.
Input: intervals = [[1,3],[2,6],[4,8],[7,10],[12,15]]
Output: [[1,10],[12,15]] — the first four intervals chain-overlap and merge into one; [12,15] stands alone.
Common pitfalls
Sorting by the wrong endpoint for the goal.
Touching intervals (
[1,2],[2,3]) — decide if they merge.