Please use Laptop/Desktop or any other large screen for the Mock Interview Session.

Insert Interval and Overlapping bookings



YouTube Video Thumbnail
Link

Watch above sample mock interview video to see how it works.
Login and Buy Premium to Start the Interview



Insert New Range into Intervals

Insert New Range into Intervals

Problem Statement

You are given a list of non-overlapping ranges sorted by their start values. Your task is to add a new range into this list and merge any overlapping ranges if necessary.

Assume the given ranges are already sorted according to their start values.

Examples

Example 1:
Ranges = [[2,4],[7,10]], newRange = [3,6]
Result: [[2,6],[7,10]]

Example 2:
Ranges = [[1,3],[5,7],[8,12],[14,16]], newRange = [6,9]
Result: [[1,3],[5,12],[14,16]]
    

Constraints

  • 1 ≤ number of ranges ≤ 10,000
  • Each range is represented as a list of two integers [start, end]
  • Ranges are initially sorted by their start values
  • The new range's start and end values will be integers in the range [0, 10^6]