4025. Minimize the Maximum Waiting Time at Synchronized Traffic Lights
You are given an integer
periodand an integer arraylights, wherelights[i]is the duration, in seconds, of the green phase of thei^thtraffic light.At time 0, every traffic light starts at the beginning of its green phase. Their cycles are synchronized: every traffic light starts a new cycle at the same time, and every cycle lasts exactly
periodseconds. Therefore, the red phase of thei_thtraffic light lasts forperiod - lights[i]seconds.You are also given an integer array
arrivalTime, wherearrivalTime[j]is the arrival time, in seconds, of thej^thcar.Each car must be assigned to exactly one traffic light. Multiple cars may be assigned to the same traffic light. Any number of cars may cross the same traffic light simultaneously while it is green. Cars do not block or delay one another.
For a car
jassigned to thei^thtraffic light, letr = arrivalTime[j] % period. Ifr < lights[i], its waiting time is 0. Otherwise, its waiting time isperiod - r.The penalty of an assignment is the maximum waiting time among all cars.
Return an integer denoting the minimum possible penalty.
1 | class Solution { |