Insert Interval

Given a sorted list of non-overlapping intervals `intervals` and a new interval `newInterval`, insert the new interval into intervals (merge if necessary) and return the updated list of intervals. **Pattern focus:** Merge Overlapping Ranges. Focus on correctness for edge cases.

Examples

Example 1:

Input:

intervals = [[1,3],[6,9]]
newInterval = [2,5]

Output:

[[1,5],[6,9]]

Explanation:

Inserted [2,5] overlaps with [1,3], merging into [1,5].

Example 2:

Input:

intervals = [[1,5]]
newInterval = [6,8]

Output:

[[1,5],[6,8]]

Explanation:

Inserted [6,8] does not overlap; it is appended.

Loading...
Insert Interval - Intervals DSA Problem