Merge Overlapping Intervals

You are given a two dimensional array containing arrays of intervals and a new interval array as arguments. Merge the inner arrays of intervals with the new interval so that there is no overlapping. Return the merged array of intervals.

The 2D array of intervals will have no overlapping to start with.

Requirements

  • Must return a two dimensional array containing arrays of intervals

Example #1

solve([[1,2], [5, 9], [12, 14]], [11, 13])
> [[1,2], [5,9], [11, 14]]

  1. We determine that intervals \[1,2] and \[5,9] do not overlap with \[11,14].
  2. We determine that \[12, 14], \[11, 13] do overlap with \[11,14], so they are merged and become \[11, 14].
  3. We return the new merged array of intervals \[\[1,2], \[5,9], \[11, 14]\]