Given a collection of intervals, merge all overlapping intervals and return the resulting set of disjoint intervals. Sorting by start time is the key that unlocks the linear merge pass.
intervals = array of [start, end]
merged non-overlapping intervals
Example 1:
Input:
intervals = [[1,3],[2,6],[8,10],[15,18]]
Output:
[[1,6],[8,10],[15,18]]
Explanation:
Intervals [1,3] and [2,6] overlap, so they merge into [1,6].
Example 2:
Input:
intervals = [[1,4],[4,5]]
Output:
[[1,5]]
Explanation:
Touching intervals are merged as overlapping at boundary 4.