Skip to main content
LeetCode 2594, Medium. Topics: Array, Binary Search. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 18 parametrized pytest cases, and a playground notebook:

Problem

You are given an integer array <code>ranks</code> representing the <strong>ranks</strong> of some mechanics. <code>ranks[i]</code> is the rank of the <code>i<sup>th</sup></code> mechanic. A mechanic with a rank <code>r</code> can repair <code>n</code> cars in <code>r * n<sup>2</sup></code> minutes. You are also given an integer <code>cars</code> representing the total number of cars waiting in the garage to be repaired. Return <em>the <strong>minimum</strong> time taken to repair all the cars.</em> <strong>Note:</strong> All the mechanics can repair the cars simultaneously.

Examples

Constraints

  • 1 <= ranks.length <= 10<sup>5</sup>
  • 1 <= ranks[i] <= 100
  • 1 <= cars <= 10<sup>6</sup>

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026