Medium · Intervals

Insert Interval

You are given a list of intervals, sorted by start and not overlapping, and one new interval. Insert it, merging anything it overlaps. Return the list, still sorted and not overlapping.

  • Each interval is [start, end] with start no greater than end.
  • Intervals that only touch, like [1, 3] and [3, 5], count as overlapping.
  • The list can be empty.
intervals = [[1, 3], [6, 9]]
added     = [2, 5]

→ [[1, 5], [6, 9]]
Record your take

No one has solved it yet.