← All patterns
5 / 32
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

  1. Inputs are [start, end] ranges?
  2. Merge, count overlaps, or insert into a schedule?
  3. 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.

Watch it run

Common pitfalls

Sorting by the wrong endpoint for the goal.

Touching intervals ([1,2], [2,3]) — decide if they merge.