Insert Interval

You are given an array of non-overlapping intervals sorted in ascending order by the start value, and a new interval. Insert the new interval into the list, merging overlapping intervals as needed, while maintaining the sorted order. Return the updated list of intervals.

Constraints

  • 0 <= intervals.length <= 10000
  • intervals[i].length == 2
  • 0 <= start_i <= end_i <= 100000
  • intervals is sorted by start_i in ascending order.
  • newInterval.length == 2
  • 0 <= start <= end <= 100000
Saving… · 2 lines
class Solution:
def insertInterval(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:
Console

Click Run to execute sample tests.