Minimum Time to Repair Cars

You are given an integer array ranks representing the ranks of some mechanics. ranks[i] is the rank of the i^th mechanic. A mechanic with a rank r can repair n cars in r * n^2 minutes.

You are also given an integer cars representing the total number of cars waiting in the garage to be repaired.

Return the minimum time taken to repair all the cars.

Note: All the mechanics can repair the cars simultaneously.

Example 1
Inputranks = [4,2,3,1], cars = 10
Output16
Assigning 2, 2, 2, and 4 cars to the mechanics takes at most 16 minutes, and it can be proved that fewer than 16 minutes is impossible.
Example 2
Inputranks = [5,1,8], cars = 6
Output16
Assigning 1, 4, and 1 cars to the mechanics takes at most 16 minutes, and it can be proved that fewer than 16 minutes is impossible.

Constraints

  • 1 <= ranks.length <= 10^5
  • 1 <= ranks[i] <= 100
  • 1 <= cars <= 10^6

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate