Given a collection of intervals, merge all overlapping intervals and return the result sorted by start.
Examples
Input:[[1,3],[2,6],[8,10],[15,18]]
Output:[[1,6],[8,10],[15,18]]
Input:[[1,4],[4,5]]
Output:[[1,5]]
Hints
After sorting, initialize an empty result list and add the first interval to it.
Iterate through the sorted intervals, comparing the start of the current interval with the end of the last interval in the result list. If they overlap, merge them by updating the end of the last interval to be the maximum of the two ends.
If they don't overlap, add the current interval to the result list as a new interval.