Insert Interval

Try to solve the Insert Interval problem.

Statement

Given a sorted list of nonoverlapping intervals and a new interval, your task is to insert the new interval into the correct position while ensuring that the resulting list of intervals remains sorted and nonoverlapping. Each interval is a pair of nonnegative numbers, the first being the start time and the second being the end time of the interval.

Constraints:

  • 0≤0 \leq existing_intervals.length ≤104\leq 10^4

  • existing_intervals[i].length, new_interval.length == 2

  • 0≤0 \leq start time << end time ≤104\leq 10^4

  • The list of intervals is sorted in ascending order based on the start timestart ~time.

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