FunctionRacerProblemsRace

Keep the Laptops Running

HardSorting and searchingPython, JavaScript, TypeScript, Java, C++

You have laptops laptops and a pile of batteries; battery i lasts batteries[i] minutes. A laptop runs on one battery at a time, and a battery powers one laptop at a time. Batteries can be swapped between laptops at any moment, as often as you like, and a swap takes no time. Batteries cannot be recharged.

Return the largest whole number of minutes for which all the laptops can run at the same time.

Example 1

laptops 2
batteries [5,2,2]
returns 4

One laptop runs on the 5 for four minutes. The other uses one 2 and then the other 2.

Example 2

laptops 2
batteries [10,1]
returns 1

The small battery lasts one minute, and the big one cannot power two laptops at once.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Sorting and searching problems