Minimum Time to Repair Cars

Medium Topics Company Tags

Mechanic i has rank ranks[i]. Assigning x cars to a mechanic of rank r takes r * x * x minutes. The mechanics work at the same time, and you may distribute the cars cars among them however you choose. Return the minimum elapsed time until every car is repaired.

Example 1:

Input: ranks = [1,2]
cars = 4

Output: 8

Explanation: Give two cars to each mechanic. They take 4 and 8 minutes, finishing in 8. Before minute 8, the first can finish at most two and the second at most one, so four cars cannot be completed sooner.

Example 2:

Input: ranks = [3]
cars = 2

Output: 12

Explanation: The only mechanic must repair both cars, taking 3 * 2 * 2 = 12 minutes.

Example 3:

Input: ranks = [2,2]
cars = 3

Output: 8

Explanation: One mechanic repairs two cars and the other repairs one, taking 8 and 2 minutes. Before minute 8, each can finish at most one car, so 8 is minimal.

Constraints:

  • 1 <= ranks.length <= 100000
  • 1 <= ranks[i] <= 100
  • 1 <= cars <= 1000000


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.