Solution: Merge Intervals

Statement

We are given an array of closed intervalsclosedintervals, intervals, where each interval has a start time and an end time. The input array is sorted with respect to the start times of each interval. For example, intervals = [ [1,4], [3,6], [7,9] ][~[1,4], ~[3,6], ~[7,9]~] is sorted in terms of start times 1, 31, ~3, and 77.

Your task is to merge the overlapping intervalsOverlapping intervals have at least one time (start/end) in common. and return a new output array consisting of only the non-overlapping intervals.

Constraints:

  • 11 \leq intervals.length 104\leq 10^4
  • intervals[i].length =2= 2
  • 00 \leq start time \leq end time 104\leq 10^4

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.