LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 1420ms, memory 30.4MB, accepted 2025-12-29.

python
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

Source