Medium · Intervals

Merge Intervals

You are given a list of intervals, each a pair [start, end]. Wherever two intervals overlap, join them into one. Return the intervals that are left, none of them overlapping.

  • Intervals that only touch count as overlapping: [1, 4] and [4, 5] become [1, 5].
  • The input is not sorted.
  • The result can be in any order.
intervals = [[1,3], [2,6], [8,10], [15,18]]

→ [[1,6], [8,10], [15,18]]   ([1,3] and [2,6] overlap)
Record your take

No one has solved it yet.