Skip to main content
Back to problems
Leetcode
Medium
Binary Search
Math
Number Theory
Google
Minimum Time To Repair Cars

Find the minimum time needed for a group of mechanics to repair all cars, where each mechanic's repair speed depends on their rank.

Acceptance 0%
Problem Statement

Problem

You are given an array of mechanic ranks and an integer cars. Each mechanic with rank r needs r * n^2 minutes to repair n cars.

All mechanics can work in parallel, and each mechanic may repair any nonnegative number of cars. Determine the minimum time required to repair at least cars cars in total.

Goal

Return the smallest integer time t such that the mechanics can collectively finish repairing all cars within t minutes.

Input Format

  • ranks: an array of positive integers, where ranks[i] is the rank of mechanic i
  • cars: a positive integer

The exact platform signature may vary, but the core input is the ranks array and the number of cars.

Output Format

  • Return the minimum integer time needed to repair at least cars cars.

Constraints

  • Each mechanic with rank r can repair n cars in r * n^2 minutes.
  • Mechanics work independently and in parallel.
  • The answer fits in 64-bit signed integer range.
  • Use the smallest feasible time.
Examples
Sample cases returned by the problem API.

Example 1

Input

ranks = [4, 2, 3, 1], cars = 10

Output

16

Explanation

In 16 minutes, the mechanics can repair at least 10 cars in total. Any smaller time is not enough.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.