Merge Intervals

Problem Given a collection of intervals, merge all overlapping intervals and return the resulting non-overlapping set.

Input / Output

  • Input: array of intervals [[start, end], ...].
  • Output: the merged, non-overlapping intervals (sorted by start).

Constraints

  • 1 ≤ n ≤ 10^4.
  • Intervals may be given in any order; touching intervals (end == next start) are typically treated as overlapping.

Example

  • [[1,3],[2,6],[8,10],[15,18]] → [[1,6],[8,10],[15,18]]
  • [[1,4],[4,5]] → [[1,5]] (touching intervals merge).
added …
LeaderboardSalaryAccount