Merge Intervals
medium · intervals
You are given a list of intervals, where each interval is a pair [start, end]. Two intervals overlap if one starts before or at the point where the other ends. Merge every group of overlapping intervals into a single interval and return the merged intervals in order of increasing start.
Input: `intervals` (a list of [start, end] pairs).
Output: the list of merged intervals, sorted by start.
Example: intervals = [[1, 3], [2, 6], [8, 10], [15, 18]] -> [[1, 6], [8, 10], [15, 18]].
Starter code
def merge(intervals: list[list[int]]) -> list[list[int]]:
"""Merge all overlapping intervals and return the merged list."""
pass
Enable JavaScript to edit this code and run the hidden tests in your browser. Each test has a five-second execution limit. Your drafts and solved progress stay in this browser.
Return to the Python compiler