Maximum Running Time of N Computers
Master this topic with zero to advance depth.
Maximum Running Time of N Computers
You have n computers and batteries. Return the maximum number of minutes you can run all n computers simultaneously.
Examples
Input: n = 2, batteries = [3,3,3]
Output: 4
Approach 1
Level I: Brute Force
Intuition
The maximum possible time is the average energy: .
⏱ $O(M)$💾 $O(1)$
Detailed Dry Run
n=2, batteries=[3,3,3]. Sum=9. Average=4.5. Result: 4.
Approach 2
Level III: Optimal (Binary Search on Answer)
Intuition
For a time , a battery with capacity can contribute at most minutes. Check if .
⏱ $O(M \\log(Sum/N))$💾 $O(1)$
Detailed Dry Run
| Step | L | R | Mid | Energy | Needed | Decision |
|---|---|---|---|---|---|---|
| 1 | 1 | 4 | 3 | 9 | 6 | L = 3 |
| 2 | 3 | 4 | 4 | 9 | 8 | L = 4 |
| Exit | - | - | - | - | - | Return 4 |
Found an issue or have a suggestion?
Help us improve! Report bugs or suggest new features on our Telegram group.