Merge Intervals
Given an array intervals where intervals[i] = [start_i, end_i], merge all overlapping intervals and return an array of the non-overlapping intervals that cover all the intervals in the input.
Open official problem prompt ↗Take a pile of possibly-overlapping ranges and produce the smallest set of disjoint ranges that covers exactly the same points.
Think of highlighting overlapping stretches on a calendar: any two marks that touch or overlap become one continuous highlighted block.
- Input
- intervals = [[1,3],[2,6],[8,10],[15,18]]
- Output
- [[1,6],[8,10],[15,18]]
- Why
- [1,3] and [2,6] overlap (3 >= 2) so they combine into [1,6]; the other two touch nothing.
1 <= intervals.length <= 10^4intervals[i].length == 20 <= start_i <= end_i <= 10^4