AlgoPlus//structures / merge-intervals
Read the theory

Merge Intervals

Sort by start, then sweep — extend the current interval whenever the next overlaps.

Intervals
6
Merged
0
Your intervals (start-end, comma-separated)
Legend
Considering
Merged result
AI Tutor Workspace
In a nutshell
Merge Intervals fuses overlapping ranges — like combining busy slots on a calendar — into the fewest blocks. Sorting them by start time means any overlap can only be with the block you're currently holding, so a single left-to-right sweep is enough: if the next range overlaps, stretch the current block's end; if it doesn't, the current block is final and a new one begins. The cost is dominated by the sort.
Ready
Press play to begin the cinematic walkthrough.
Sort intervals by start; then sweep left to right, extending the current interval whenever the next one overlaps it.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Merge Intervals.