Code RoomInsert interval merge
MediumPrep Room Coding #1233

Insert interval merge

CodingAlgorithms & data structuresMid–Senior~22 min

You are given `intervals`, a list of non-overlapping intervals [start, end] sorted ascending by start, and a single `new_interval` [start, end]. Insert the new interval and merge as needed so the result remains sorted and non-overlapping. Return the new list. Two intervals overlap (and merge) if they touch — i.e. [1,2] and [2,3] merge into [1,3]. Up to 10^4 intervals; aim for O(n) with a single pass.

Implement
insert_interval(intervals: list[list[int]], new_interval: list[int]) → list[list[int]]
Examples
in[[[1,3],[6,9]],[2,5]]out[[1,5],[6,9]]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 22 min
InputExpectedGot
[[[1,3],[6,9]],[2,5]][[1,5],[6,9]]not run yetsample