Back to problems

Insert Intervals with Set

Algorithm · Oracle · Medium

You are given a collection of pairwise non-overlapping intervals, intervals, along with an additional interval, newInterval. Add newInterval so that the resulting collection is still ordered and contains no overlapping ranges, merging ranges whenever necessary. You may assume the set orders its elements automatically. Implement the algorithm below and discuss its time complexity. Example Explanation: The new interval intersects both existing intervals, so all three combine…

Checking your access…