
In a Meta scheduling pipeline, you are given a list of time ranges representing busy windows for a service or model job. Merge all overlapping time ranges and return the minimal set of non-overlapping ranges covering the same time.
Implement a function that takes intervals, a list of intervals where each interval is a list [start, end] with start <= end, and returns 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_start, max_end].
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^9intervals = [[1,3],[2,6],[8,10],[15,18]]Output[[1,6],[8,10],[15,18]]WhyThe first two intervals overlap and merge into `[1,6]`. The remaining intervals do not overlap with that merged range.intervals = [[1,4],[4,5]]Output[[1,5]]WhyBecause touching endpoints are treated as overlapping, `[1,4]` and `[4,5]` merge into one interval.intervals = [[5,7],[1,2],[2,4]]Output[[1,4],[5,7]]WhyAfter sorting, `[1,2]` and `[2,4]` merge, while `[5,7]` remains separate.0 <= len(intervals) <= 10^5intervals[i].length == 20 <= start <= end <= 10^9Each interval is represented as [start, end]Intervals that touch at endpoints should be mergeddef merge_intervals(intervals):