Merge Intervals
Medium
Arrays
Sorting
Intervals
Given an array of intervals [start, end], merge all overlapping intervals.
Input: intervals one per line as 'start end'
Output: merged intervals one per line
Constraints
1 <= intervals.length <= 10000
intervals[i].length == 2
0 <= start <= end <= 10000
Examples
Example 1:
Input: 1 3
2 6
8 10
15 18
Output:
Example 2:
Input: 1 4
4 5
Output:
Hints
Sort by start time.
Merge if current start <= previous end.
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console