Code RoomMost clashing reservation
MediumPrep Room Coding #4908

Most clashing reservation

CodingAlgorithms & data structuresMid–Senior~25 min

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.

Implement
worst_clash_index(starts: list[int], ends: list[int]) → int
Examples
in[[0,4,5,20],[3,12,7,25]]out1
in[[0,10,20],[5,15,25]]out0
in[[1,4,8,0],[2,5,9,12]]out3
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 25 min
InputExpectedGot
[[0,4,5,20],[3,12,7,25]]1not run yetsample
[[0,10,20],[5,15,25]]0not run yetsample
[[1,4,8,0],[2,5,9,12]]3not run yetsample