Optimal freeze window

Write codeHard35 min

Your task

A build farm repeats the same job calendar every cycle minutes, so minute cycle minus 1 is followed by minute 0 again. Job i is booked at starts[i], a minute in 0 through cycle minus 1, and holds the farm for the minutes starts[i] through ends[i] minus 1 counted around the wrap, so ends[i] is at least starts[i] and never more than starts[i] plus cycle. A job with ends[i] equal to starts[i] holds nothing. The release team must place one freeze of freeze_len consecutive minutes, starting at any minute in 0 through cycle minus 1 and wrapping the same way, with freeze_len at least 1 and at most cycle. A job clashes with the freeze when the two share at least one minute. Return the freeze start clashing with the fewest jobs, breaking ties by the smallest start minute. cycle can be as large as 10^9.

Examples

best_freeze_start(starts: list[int], ends: list[int], freeze_len: int, cycle: int) -> int
Example 1
Inputbest_freeze_start([0, 20], [10, 30], 5, 40)
Output10
Example 2
Inputbest_freeze_start([50], [58], 4, 60)
Output0
Example 3
Inputbest_freeze_start([], [], 7, 24)
Output0