The Maximum Running Time of N Computers interview question is a high-level scheduling and load-balancing problem. You have n computers and a set of batteries with various capacities. You want to run all n computers simultaneously for as long as possible using these batteries. You can swap batteries between computers at any time, and the swap is instantaneous.
The goal is to find the maximum time T such that all n computers can run for T minutes.
This Maximum Running Time of N Computers coding problem is a "Hard" difficulty question asked by Flipkart and Google. It tests your ability to recognize a "Binary Search on Answer" pattern. It's not immediately obvious that you can check if a time T is possible. It evaluates your ability to handle large constraints and find a non-obvious greedy condition that determines feasibility.
The Array, Sorting, Binary Search, Greedy interview pattern is applied here.
sum(batteries) / n.T.T, check if it's feasible:
T minutes to the total pool (since it can only be in one computer at a time).T is sum(min(battery_capacity, T) for battery in batteries).total_energy >= n * T, then time T is feasible.n = 2 computers, batteries = [3, 3, 3].
The biggest mistake in the Maximum Running Time of N Computers coding problem is trying to use a greedy approach like "always use the largest batteries first" without the binary search framework. This fails because of the swapping rule. Another mistake is not capping the battery contribution at T in the feasibility check. Candidates also often struggle with the data types, as the total sum of battery capacities can exceed the range of a 32-bit integer.
Whenever you are asked to "maximize the minimum" or "find the maximum possible value" and there's a clear range, always consider Binary Search on the result. The key is to simplify the problem into a "Can I do this for value X?" question, which is often much easier to answer than finding the optimal value directly.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Maximize Score of Numbers in Ranges | Medium | Solve | |
| Maximum Number of Integers to Choose From a Range II | Medium | Solve | |
| Maximum Tastiness of Candy Basket | Medium | Solve | |
| Minimum Time to Complete All Tasks | Hard | Solve | |
| Minimum Cost to Make Array Equal | Hard | Solve |