Insert Interval
You are given an array of non-overlapping intervals intervals where intervals[i] = [starti, endi] represent the start and the end of the ith interval and intervals is sorted in ascending order by starti. You are also given an interval newInterval = [start, end] that represents the start and end of another interval. Insert newInterval into intervals such that intervals is still sorted in ascending order by starti and intervals still does not have any overlapping intervals (merge overlapping intervals if necessary).

30:00

Insert Interval
medium
Topics
Companies

You are given an array of non-overlapping intervals intervals where intervals[i] = [starti, endi] represent the start and the end of the ith interval and intervals is sorted in ascending order by starti. You are also given an interval newInterval = [start, end] that represents the start and end of another interval. Insert newInterval into intervals such that intervals is still sorted in ascending order by starti and intervals still does not have any overlapping intervals (merge overlapping intervals if necessary).

Example 1:
Input: {"intervals":[[1,3],[6,9]],"newInterval":[1,5]}
Output: [[1,5],[6,9]]
Constraints:
  • 0intervals.length1040 \leq \text{intervals.length} \leq 10^4

  • intervals[i].length==2\text{intervals}[i].\text{length} == 2

  • 0startiendi1050 \leq \text{start}_i \leq \text{end}_i \leq 10^5

  • intervals is sorted by starti\text{start}_i in ascending order.

  • newInterval.length==2\text{newInterval.length} == 2, 0startend1050 \leq \text{start} \leq \text{end} \leq 10^5

Input
arr ={"intervals":[[1,3],[6,9]],"newInterval":[1,5]}

Start

[1,5]
[1,3]
[6,9]
Prev End
-Inf
Removed Count
0
Variables
No variables to display
DepthFunction Call
Stack empty
0/5