Insert an Interval into a Schedule

medium
Unit 19 · Selection0/3 to milestone

A calendar holds sorted, non-overlapping busy intervals [start, end]. Insert a new booking and merge any overlaps, in one linear pass, without re-sorting.

Implement insert_interval(intervals, new). Intervals that touch (end == start) merge. Don't modify the input.

Then implement free_slots(intervals, day_start, day_end, min_length=1): the gaps of at least min_length between day_start and day_end, given busy intervals that may overlap and be unsorted.

#intervals#arrays2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Insert an Interval into a Schedule · TechGradify