Tap here to switch tabs
Problem
Ask
Submissions

Problem: Insert Interval

med
30 min
Understand how to insert a new interval into a sorted list of non-overlapping intervals. Learn to merge overlapping intervals effectively and return an updated sorted list without overlaps.

Statement

You are given a list of non-overlapping intervals, intervals, where each interval is represented as [starti, endi] and the list is sorted in ascending order by the start of each interval (starti). You are also given another interval, new_interval = [start, end].

Your task is to insert new_interval into the list of intervals such that the list remains sorted by starting times and still contains no overlapping intervalsOverlapping intervals are two or more intervals with at least one common point in time.. If any intervals overlap after the insertion, merge them accordingly.

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:

  • 00 \leq intervals.length 104\leq 10^4

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

  • 00 \leq starti << endi 104\leq 10^4

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

Tap here to switch tabs
Problem
Ask
Submissions

Problem: Insert Interval

med
30 min
Understand how to insert a new interval into a sorted list of non-overlapping intervals. Learn to merge overlapping intervals effectively and return an updated sorted list without overlaps.

Statement

You are given a list of non-overlapping intervals, intervals, where each interval is represented as [starti, endi] and the list is sorted in ascending order by the start of each interval (starti). You are also given another interval, new_interval = [start, end].

Your task is to insert new_interval into the list of intervals such that the list remains sorted by starting times and still contains no overlapping intervalsOverlapping intervals are two or more intervals with at least one common point in time.. If any intervals overlap after the insertion, merge them accordingly.

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:

  • 00 \leq intervals.length 104\leq 10^4

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

  • 00 \leq starti << endi 104\leq 10^4

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