Code RoomEnvironment contention minutes
MediumPrep Room Coding #4907

Environment contention minutes

CodingAlgorithms & data structuresMid–Senior~25 min

Several product teams book one staging environment. Three parallel lists describe the reservations: reservation i is taken out by team team_ids[i] and covers every minute from starts[i] up to but not including ends[i]. Two reservations that meet at a single boundary therefore share no minute. The list is unsorted, and ends[i] is never below starts[i]. A team may reserve the environment twice across the same stretch, which is allowed and harmless. The environment is contended during a minute when two or more different teams both hold a reservation across it. A reservation whose two bounds are identical books no time at all. Return the total number of contended minutes, tallying a minute a single time no matter how deep the pile of reservations sitting on it.

Implement
contended_minutes(starts: list[int], ends: list[int], team_ids: list[int]) → int
Examples
in[[0,30],[60,90],[1,2]]out30
in[[0,30],[60,90],[7,7]]out0
in[[0,60],[60,120],[1,2]]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 25 min
InputExpectedGot
[[0,30],[60,90],[1,2]]30not run yetsample
[[0,30],[60,90],[7,7]]0not run yetsample
[[0,60],[60,120],[1,2]]0not run yetsample