Insert Interval
Try to solve the Insert Interval problem.
We'll cover the following
Statement
You are given a list of non-overlapping intervals, intervals
, where each interval is represented as [start
i
, end
i
]
and the list is sorted in ascending order by the start of each interval (start
i
). You are also given another interval, newInterval = [start, end]
.
Your task is to insert newInterval
into the list of intervals such that the list remains sorted by starting times and still contains no
Return the updated list of intervals.
Note: You don’t need to modify
intervals
in place. You can make a new array and return it.
Constraints:
intervals.length
intervals[i].length
,newInterval.length
start
i
end
i
The list of intervals is sorted in ascending order based on the start time.
Examples
Create a free account to view this lesson.
Continue your learning journey with a 14-day free trial.
By signing up, you agree to Educative's Terms of Service and Privacy Policy