Problem
Given a list of intervals [start, end], merge every group that overlaps and return the result sorted by start. Intervals that touch (one ends where the next starts) count as overlapping.
Example 1
- Input
- [[1, 3], [2, 6], [8, 10], [15, 18]]
- Output
- [[1, 6], [8, 10], [15, 18]]
Example 2
- Input
- [[1, 4], [4, 5]]
- Output
- [[1, 5]]
Example 3
- Input
- [[4, 7], [1, 4]]
- Output
- [[1, 7]]
- Why
- input may be unsorted
Constraints
0 <= intervals.length <= 10^40 <= start <= end <= 10^4