Most clashing reservation

Write codeMedium25 min

Your task

A shared hardware lab logs equipment reservations as two parallel lists: reservation i runs from starts[i] up to but not including ends[i], and every reservation ends strictly after it starts. The log arrives in no particular order and may hold many thousands of entries. Two reservations clash when they share at least one instant, so two that merely touch, one ending exactly where the next begins, do not clash. The lab wants the single reservation caught in the most clashes before it renegotiates that slot. Return the index of the reservation clashing with the largest number of other reservations, breaking ties by the smallest index. Return -1 when the log is empty.

Examples

worst_clash_index(starts: list[int], ends: list[int]) -> int
Example 1
Inputworst_clash_index([0, 4, 5, 20], [3, 12, 7, 25])
Output1
Example 2
Inputworst_clash_index([0, 10, 20], [5, 15, 25])
Output0
Example 3
Inputworst_clash_index([1, 4, 8, 0], [2, 5, 9, 12])
Output3