Minimize the maximum redirect latency when overloaded servers shift load to servers with spare capacity.
Unlock detailed company stats for this questionUpgrade
You have n servers (0-indexed) with given capacity and on-coming load. If the load on server i is greater than its capacity, it must redirect some load to another server j that has capacity to spare. The latency to redirect load from i to j is abs(i-j). What is the minimum possible maximum latency required to distribute the load so that every server has load less than or equal to its capacity?
Example 1: capacity = [3, 2, 1, 4], load = [2, 1, 4, 3].
Example 2: capacity = [3, 2, 1, 4], load = [2, 2, 4, 2]. Answer: 2. Server 2 redirects 2 requests to server 3 and 1 request to server 0, so the answer is max(|2-3|, |2-0|) = 2.
The poster tried binary searching on the answer but missed something.
Community answers
No answers contributed by the community yet.
Related courses

Course

Course
Course
