Problem Statement
Given a list of intervals, merge all the overlapping intervals to produce a list that has only mutually exclusive intervals.
Example 1:
Intervals: [[1,4], [2,5], [7,9]]
Output: [[1,5], [7,9]]
Explanation: Since the first two intervals [1,4] and [2,5] overlap, we merged them into one [1,5].
![Image](/_next/image?url=https%3A%2F%2Fstorage.googleapis.com%2Fdownload%2Fstorage%2Fv1%2Fb%2Fdesigngurus-prod.appspot.com%2Fo%2FdocImages%252F63923e6de4cb724ea719007a%252Fimg%3A3c343cd-a460-dda-28d0-554e6b5d6553.png%3Fgeneration%3D1670528693497923%26alt%3Dmedia&w=3840&q=75)
Example 2:
Intervals: [[6,7], [2,4], [5,9]]
Output: [[2,4], [5,9]]
Explanation: Since the intervals [6,7] and [5,9] overlap, we merged them into one [5,9].
Example 3:
Intervals: [[1,4], [2,6], [3,5]]
Output: [[1,6]]
Explanation: Since all the given intervals overlap, we merged them into one.
Constraints:
- 1 <= intervals.length <= 10<sup>4<sup>
intervals[i].length == 2
- 0 <= start<sub>i</sub> <= end<sub>i</sub> <= 10<sup>4<sup>
Try it yourself
Try solving this question here:
Python3
Python3