53. Insert Interval
MediumIntervals
Given a sorted array of non-overlapping intervals `intervals` where intervals[i] = [start_i, end_i], and a new interval `newInterval = [start, end]`, insert `newInterval` into `intervals` such that `intervals` is still sorted and non-overlapping. Merge overlapping intervals if necessary and return the resulting array. For example, given intervals = [[1,3],[6,9]] and newInterval = [2,5], the new interval [2,5] overlaps with [1,3], so they merge into [1,5]. The result is [[1,5],[6,9]].
Examples
Input: [[1,3],[6,9]] [2,5]
Output: [[1,5],[6,9]]
Explanation: The new interval [2,5] overlaps with [1,3], merging into [1,5]. [6,9] is unchanged.
Constraints
- 0 <= intervals.length <= 10^4
- intervals[i].length == 2
- 0 <= start_i <= end_i <= 10^5
- intervals is sorted by start_i in ascending order
- newInterval.length == 2
- 0 <= start <= end <= 10^5
Loading...
Run checks all cases above. Submit evaluates all test cases.