Ctrl K

Repair Deadline at the Garage

Medium
Several mechanics work in a garage. Mechanic i has a factor speed[i]: repairing m cars in a row takes them speed[i] · m² minutes. The smaller the factor, the faster the mechanic. There are cars cars waiting. The mechanics work at the same time, and each car is repaired by exactly one of them. Return the smallest number of minutes in which all the cars can be repaired.
Example 1
speed=[3, 1, 2], cars=5 → 8

In 8 minutes the factor-1 mechanic manages 2 cars (1·2² = 4, while a third would need 9), the factor-2 one manages 2 (2·2² = 8) and the factor-3 one manages 1 (3·1² = 3). That makes 5. In 7 minutes it would be only 2 + 1 + 1 = 4.

Example 2
speed=[2, 2], cars=4 → 8

Each mechanic takes two cars: 2·2² = 8 minutes.

Example 3
speed=[7], cars=1 → 7
Constraints
  • 1 ≤ len(speed) ≤ 10⁵
  • 1 ≤ speed[i] ≤ 100
  • 1 ≤ cars ≤ 10⁶
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFind in a Shifted Sorted Array MediumFirst and Last Copy MediumFind in a Row-Chained Grid MediumFind in a Shifted Array With Repeats MediumMinimum of a Shifted List Medium
loading Python…
Input
speed=[3, 1, 2], cars=5
Expected
8

Run checks the first 3 tests in your browser. Submit checks all 85 tests on the server, hidden ones included.