Environment contention minutes

Write codeMedium25 min

Your task

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.

Examples

contended_minutes(starts: list[int], ends: list[int], team_ids: list[int]) -> int
Example 1
Inputcontended_minutes([0, 30], [60, 90], [1, 2])
Output30
Example 2
Inputcontended_minutes([0, 30], [60, 90], [7, 7])
Output0
Example 3
Inputcontended_minutes([0, 60], [60, 120], [1, 2])
Output0