core practice · coding problem

Merge overlapping intervals

Merge [[1,3],[2,6],[8,10],[15,18]] → ?

The mechanism

Interval problems almost always start by sorting — usually by start time, sometimes by end. After sorting, a single pass with a couple of running variables (last end, current count) handles merge, overlap, scheduling, and room allocation.

Study Intervals

Expected evidence

[[1,6],[8,10],[15,18]].

Try this drill in the practice workspace →

Hints when you need them
  • Sort by start.
  • Extend current if overlap.

Check the sources

Browse all practice briefs