Data Structures19 sections · 729 units
Open in Course

Problem - Insert Interval

Merge with new interval

Given a sorted list of non-overlapping intervals and a new interval, insert the new interval and merge if necessary. Return the result still sorted and non-overlapping.

Example: intervals =[[1,3],[6,9]]= [[1,3], [6,9]], new =[2,5]= [2,5] returns [[1,5],[6,9]][[1,5], [6,9]]. This builds on merge intervals but requires handling the insertion point. Constraints: up to 10410^4 intervals.