Code RoomCircular shift coverage
HardPrep Room Coding #4864

Circular shift coverage

CodingAlgorithms & data structuresSenior–Staff~38 min

An operations team staffs a rota for a single day of 1440 minutes, numbered 0 through 1439, and the day wraps, so minute 1439 is followed by minute 0. alert_minutes lists the minute of every page from a typical day, in no particular order and possibly with repeats. The team can schedule shifts shifts, all of the same span, each free to start at any minute and each covering a contiguous stretch of the clock. A shift of span s starting at minute m covers minute m through minute m plus s, counted around the wrap. Return the smallest span that lets those shifts cover every alerting minute. Return 0 when there are no alerts, and -1 when there are alerts but no shifts.

Implement
shortest_shift_span(alert_minutes: list[int], shifts: int) → int
Examples
in[[0,10,20,31],2]out11
in[[1430,1435,5,10],1]out20
in[[],3]out0
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 38 min
InputExpectedGot
[[0,10,20,31],2]11not run yetsample
[[1430,1435,5,10],1]20not run yetsample
[[],3]0not run yetsample