Merge Intervals
Merge overlapping closed intervals and return their union as sorted disjoint closed intervals. Touching endpoints overlap.
Example 1
intervals = [[5,8],[1,3],[3,6]][[1,8]]Explanation
[1,3] touches [3,6], which overlaps [5,8], merging the chain into [1,8].
Example 2
intervals = [[1,2],[4,5]][[1,2],[4,5]]Explanation
The gap between 2 and 4 keeps the intervals separate.
Example 3
intervals = [[2,3],[1,9]][[1,9]]Explanation
[2,3] is contained in [1,9] and adds no endpoints.
Constraints
- 1 <= number of intervals <= 10000
- Each pair has start <= end
Function contract
mergeArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[[5,8],[1,3],[3,6]]