Workspace Interval Merge
0d
Problem-solving patterns

Interval Merge

Sort by starts and maintain the union of intervals processed so far.

Recognition signal

Ranges must be coalesced or overlap tested.

Method

Extend the current end on an overlap, otherwise start a new interval.

Worked example

For closed intervals [1, 4], [3, 6], [8, 9], the first two combine into [1, 6].

Common mistake

Touching endpoints count as overlap only under the chosen interval convention.