Given an array of intervals intervals, where each interval is a pair [start, end] with start <= end, merge all overlapping intervals and return a new array of non-overlapping intervals that covers the same ranges. The output may be returned in any order, but a sorted merged result is preferred.
Example 1:
Input: intervals = [[1,3],[2,6],[8,10],[15,18]]
Output: [[1,6],[8,10],[15,18]]
Explanation: [1,3] and [2,6] overlap, so they merge into [1,6].
Example 2:
Input: intervals = [[1,4],[4,5]]
Output: [[1,5]]
Explanation: Intervals that touch at an endpoint are considered overlapping.
1 <= len(intervals) <= 10^4intervals[i].length == 20 <= start <= end <= 10^4