




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^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 into `[1,4]`, while `[5,7]` remains separate.0 <= len(intervals) <= 10^5intervals[i].length == 20 <= start <= end <= 10^9The input intervals may be unsorteddef merge_intervals(intervals):