Skip to main content
All Questions

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

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.