The list intervals holds time slots. Each slot [start, end] is one booking, for example a meeting room that is booked from hour start to hour end.
Merge all the slots that overlap, and return the merged slots. Two slots that only touch, like [1,3] and [3,6], also count as overlapping. The result must have no overlaps and must cover exactly the same time as the input. Return the merged slots sorted by their start.
Examples
Example 1:
Input: intervals = [[2,5],[4,8],[10,12],[11,15]]
Output: [[2,8],[10,15]]
Explanation: [2,5] and [4,8] overlap, so they become [2,8]. [10,12] and [11,15] overlap, so they become [10,15].
Example 2:
Input: intervals = [[1,3],[3,6]]
Output: [[1,6]]
Explanation: The two slots touch at 3, so they merge into [1,6].
Example 3:
Input: intervals = [[7,9],[1,2],[4,5]]
Output: [[1,2],[4,5],[7,9]]
Explanation: No two slots overlap. The input may come in any order, so sort the answer by start.