Intervals
Sort and reason about ranges to merge overlaps, find conflicts, or select non-overlapping intervals.
Inputs contain start/end pairs, meetings, bookings, or ranges that can overlap or touch.
How to approach it
For merging, sort by start and extend the current interval while the next start overlaps; otherwise emit and begin another.
Clarify whether touching endpoints count as overlapping and whether intervals are open, closed, or half-open.
Practice question
Merge overlapping intervals in [[1, 3], [2, 5], [7, 8]].
intervals = [[1, 3], [2, 5], [7, 8]]Give your answer before revealing the explanation.Show a hint
Sort by start and compare each interval with the end of the merged range.
Show an answer
[[1, 5], [7, 8]]
Intervals at work
A clinic has appointment blocks [9:00, 10:00], [9:30, 10:30], and [11:00, 11:30]. What busy ranges should appear on the staff calendar?
Show one possible approach
[9:00, 10:30] and [11:00, 11:30]. Sort by start and merge the first two because they overlap.
Practice next
Use these problem IDs to find additional practice for this pattern: