← Practice · Intervals
Merge Intervals Medium
Given an array of intervals [start, end], merge all overlapping intervals and return the non-overlapping intervals covering the same ranges, sorted by start. Intervals that touch at an endpoint overlap.
Examples
[[1,3],[2,6],[8,10],[15,18]] -> [[1,6],[8,10],[15,18]][[1,4],[4,5]] -> [[1,5]]
Define a function named merge in JavaScript.
00:00▶ Visualize
JavaScript · Tab indents · Ctrl/⌘+Enter runs the tests