Practice/FanDuel/Leetcode 57. Insert Interval
CodingMust
You are building a calendar system that manages meeting time slots. Given a collection of non-overlapping time intervals that are already sorted by their start times, insert a new time interval into this collection. After insertion, merge any overlapping intervals to ensure the final collection remains sorted and contains no overlaps.
Each interval is represented as a pair of integers [start, end] where start is the beginning time and end is the ending time of the interval.
0 <= intervals.length <= 10^4intervals[i].length == 20 <= start_i < end_i <= 10^6intervals is sorted by start_i in ascending ordernewInterval.length == 20 <= newInterval[0] < newInterval[1] <= 10^6Example 1:
Input: intervals = [[1,3],[6,9]], newInterval = [2,5] Output: [[1,5],[6,9]] Explanation: The new interval [2,5] overlaps with [1,3], so they merge into [1,5]
Example 2:
Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8] Output: [[1,2],[3,10],[12,16]] Explanation: The interval [4,8] overlaps with [3,5], [6,7], and [8,10], merging them all
Example 3:
Input: intervals = [], newInterval = [5,7] Output: [[5,7]] Explanation: With no existing intervals, return just the new interval