Given an array of intervals where intervals[i] = [start_i, end_i], merge all overlapping intervals and return a list of the merged intervals. **Pattern focus:** Sort by Start Time. Focus on correctness for small and boundary inputs.
Example 1:
Input:
intervals = [[1,3],[2,6],[8,10],[15,18]]
Output:
[[1,6],[8,10],[15,18]]
Explanation:
Overlapping intervals [1,3] and [2,6] merge into [1,6].
Example 2:
Input:
intervals = [[1,4],[5,8]]
Output:
[[1,4],[5,8]]
Explanation:
No intervals overlap; output is same as input.