Trains the technique from
LeetCode 57Insert IntervalThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A rehearsal room stores its booked blocks in intervals. Each block is a pair
[from, to] giving the minute the block opens and the minute it closes. The
blocks are listed from earliest opening to latest, and no two of them share even
a single minute, not even an endpoint.
A fresh request arrives as newInterval, another [from, to] pair. Put it on
the schedule. Every booked block the request runs into fuses with it into one
longer block, and blocks that merely meet the request at an endpoint count as
running into it.
Return the schedule after the request has been placed: a list of blocks ordered by opening minute, with no two blocks overlapping or meeting.
Example 1
The request covers minutes 2 through 7, so it runs into [1,3] and into [6,9]; those two and the request fuse into [1,9]. The block [12,14] is left alone.
Example 2
The request closes on the same minute the booked block opens, and meeting at an endpoint counts, so the two fuse into [2,8].
Example 3
Nothing is booked, so the schedule is the request on its own.
Example 4
The request runs into [5,6] and [8,10], and the three fuse into [4,10]. It opens at minute 4 while [1,3] closes at minute 3, so those two neither overlap nor meet, and [14,16] is untouched.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def insert(intervals: list[list[int]], newInterval: list[int]) -> list[list[int]]:public int[][] insert(int[][] intervals, int[] newInterval)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.