Support rota coverage gaps

Write codeEasy16 min

Your task

A team publishes its overnight support rota as a list of shifts, each written as a pair [start, end] in minutes counted from midnight. A shift covers every minute from start up to but not including end. The shifts arrive in no particular order, two of them can cover the same minute, a cancelled shift can carry start equal to end, and a shift that began the previous evening can carry a negative start. The rota is meant to cover the window running from minute 0 up to but not including day_end. Clip each shift to that window, then return every stretch inside the window with nobody on duty, each written as a pair [begin, finish] read the same way, sorted by begin. Return an empty list when the window is covered end to end, and also when day_end is zero or negative.

Examples

oncall_coverage_gaps(shifts: list[list[int]], day_end: int) -> list[list[int]]
Example 1
Inputoncall_coverage_gaps([[0, 480], [480, 960]], 1440)
Output[[960, 1440]]
Example 2
Inputoncall_coverage_gaps([[120, 300], [240, 400], [600, 660]], 720)
Output[[0, 120], [400, 600], [660, 720]]
Example 3
Inputoncall_coverage_gaps([], 60)
Output[[0, 60]]