Given a set of non-overlapping intervals sorted by start time, and a new interval, insert the new interval into the set, merging any overlapping intervals, and return the resulting sorted list.
intervals = [[1,3],[6,9]], newInterval = [2,5][[1,5],[6,9]]intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8][[1,2],[3,10],[12,16]]Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →Problems about ranges — meeting times, event schedules, ranges on a number line — almost always start with sorting the intervals by start (or end) time, then sweeping through them once.
Read the full Intervals guide →
Original problem on LeetCode ↗