56. Merge Intervals
Practice Merge Intervals for free on NudgeCode: Medium, Greedy pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Given a list of [start, end] intervals in any order, merge every group of overlapping intervals (touching ends count as overlapping) and return the merged intervals. The order of the result doesn't matter.
Example
intervals = [[1,3],[2,6],[8,10],[15,18]] -> [[1,6],[8,10],[15,18]]
intervals = [[1,4],[4,5]] -> [[1,5]]
Constraints
- 1 <= intervals.length <= 10^4
- 0 <= start <= end <= 10^4