Imagine you're managing a data center with n computers that need to run simultaneously for as long as possible. You have a collection of rechargeable batteries, each with different capacities measured in minutes.
Here's the challenge: You can hot-swap batteries between computers at any time - meaning you can remove a depleted battery from one computer and instantly insert it into another, or swap in a fresh battery. The goal is to keep all n computers running simultaneously for the maximum possible duration.
Input: An integer n (number of computers) and an array batteries where batteries[i] represents the capacity of the i-th battery in minutes.
Output: The maximum number of minutes you can keep all n computers running simultaneously.
Key Insight: This isn't about assigning batteries to computers - it's about optimally distributing the total battery capacity across time to maximize runtime!
Input & Output
Constraints
- 1 โค n โค 105
- 1 โค batteries.length โค 105
- 1 โค batteries[i] โค 109
- You can hot-swap batteries between computers at any integer time moment