mediumIntervalsFacebookGoogle
Overlap Collapser
A calendar app collapses any overlapping meetings into single union intervals.
Given an array of intervals, merge all overlapping intervals and return the non-overlapping intervals that cover all input intervals.
Choose approach
1/5
Narrationstep 1 of 5
I0 starts a new output interval.
Variables
i=0
start=1
end=3
How to think about it
- Sorting makes overlap-detection local.
- Compare current with the last output only.
Edge cases to catch in interview
- Empty -> [].
- All disjoint -> same as input (sorted).
Examples
Example 1
[[1,5]]{"intervals":[[1,4],[4,5]]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed