Medium35 pts
Merge Intervals
Given an array of intervals where intervals[i] = [start, end], merge all overlapping intervals and return non-overlapping intervals. Algorithm: Sort by start time, then iterate and merge if current start ≤ previous end. Example: [[1,3],[2,6],[8,10],[15,18]] → [[1,6],[8,10],[15,18]] (intervals [1,3] and [2,6] overlap)
Input
Line 1: n (number of intervals). Next n lines: start end (space-separated).
Output
Merged intervals, one per line as 'start end'.
Sample
4 1 3 2 6 8 10 15 18
Expected
1 6 8 10 15 18
Loading editor…
Output
No output yet. Run your code to see results.