Merge Overlapping Intervals
ARRAY
Problem
Given an array of 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.
Examples
merge([[1,3],[2,4],[5,7],[6,8]]); // returns [[1,4],[5,8]] // [1,3] and [2,4] are overlapping and are merging into [1,4] // Same for [5,7] and [6,8], they are merging into [5,8] merge([[1,8],[6,10]]); // returns [[1,10]]
Loading...
1
3
2
4
5
7
6
8