In a Meta scheduling or logging pipeline, you may receive a list of time ranges that can overlap. Write a function that merges all overlapping intervals and returns a minimal list of non-overlapping intervals.
Given intervals, a list of intervals where each interval is a two-element list [start, end], return a new list of merged intervals sorted by start time.
Two intervals overlap if the next interval's start is less than or equal to the current merged interval's end. In that case, they should be combined into [min(start1, start2), max(end1, end2)].
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: The intervals touch at 4, so they are considered overlapping and should be merged.
0 <= len(intervals) <= 10^5intervals[i].length == 20 <= start <= end <= 10^9