Skip to content

Practice Maximum Running Time of N Computers

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2141
LeetCode Problem

Maximum Running Time of N Computers

Problem Statement

You have n computers. You are given the integer n and a 0-indexed integer array batteries where the ith battery can run a computer for batteries[i] minutes. You are interested in running all n computers simultaneously using the given batteries. Initially, you can insert at most one battery into each computer. After that and at any integer time moment, you can remove a battery from a computer and insert another battery any number of times. The inserted battery can be a totally new battery or a battery from another computer. You may assume that the removing and inserting processes take no time. Note that the batteries cannot be recharged. Return the maximum number of minutes you can run all the n computers simultaneously.

Source: Maximum Running Time of N Computers on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 2, batteries = [3,3,3]
Output
4

# Example 2

Input
n = 2, batteries = [1,1,1,1]
Output
2

Constraints

1 <= n <= batteries.length <= 10^5
1 <= batteries[i] <= 10^9

Related LeetCode Problems

Practice more problems similar to Maximum Running Time of N Computers.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.