2263. Maximum Running Time of N Computers
My accepted Python solution to LeetCode problem 2263, Maximum Running Time of N Computers, running in 1420ms.
- Difficulty: Hard
- Python
- Runtime 1420ms
- Memory 30.4MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 1420ms, memory 30.4MB, accepted 2025-12-29.
class Solution:
def maxRunTime(self, n: int, batteries: List[int]) -> int:
# Binary search for the answer
total = sum(batteries)
left, right = 1, total // n
while left < right:
mid = (left + right + 1) // 2
# Check if we can run n computers for mid minutes
# Each battery can contribute at most mid minutes
power = sum(min(b, mid) for b in batteries)
if power >= n * mid:
left = mid
else:
right = mid - 1
return left