java.lang.Object
g2501_2600.s2594_minimum_time_to_repair_cars.Solution

public class Solution extends Object
2594 - Minimum Time to Repair Cars.<p>Medium</p> <p>You are given an integer array <code>ranks</code> representing the <strong>ranks</strong> of some mechanics. ranks<sub>i</sub> is the rank of the i<sup>th</sup> mechanic. A mechanic with a rank <code>r</code> can repair n cars in <code>r * n<sup>2</sup></code> minutes.</p> <p>You are also given an integer <code>cars</code> representing the total number of cars waiting in the garage to be repaired.</p> <p>Return <em>the <strong>minimum</strong> time taken to repair all the cars.</em></p> <p><strong>Note:</strong> All the mechanics can repair the cars simultaneously.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> ranks = [4,2,3,1], cars = 10</p> <p><strong>Output:</strong> 16</p> <p><strong>Explanation:</strong></p> <ul> <li> <p>The first mechanic will repair two cars. The time required is 4 * 2 * 2 = 16 minutes.</p> </li> <li> <p>The second mechanic will repair two cars. The time required is 2 * 2 * 2 = 8 minutes.</p> </li> <li> <p>The third mechanic will repair two cars. The time required is 3 * 2 * 2 = 12 minutes.</p> </li> <li> <p>The fourth mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.</p> </li> </ul> <p>It can be proved that the cars cannot be repaired in less than 16 minutes.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> ranks = [5,1,8], cars = 6</p> <p><strong>Output:</strong> 16</p> <p><strong>Explanation:</strong></p> <ul> <li> <p>The first mechanic will repair one car. The time required is 5 * 1 * 1 = 5 minutes.</p> </li> <li> <p>The second mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.</p> </li> <li> <p>The third mechanic will repair one car. The time required is 8 * 1 * 1 = 8 minutes.</p> </li> </ul> <p>It can be proved that the cars cannot be repaired in less than 16 minutes.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= ranks.length <= 10<sup>5</sup></code></li> <li><code>1 <= ranks[i] <= 100</code></li> <li><code>1 <= cars <= 10<sup>6</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • repairCars

      public long repairCars(int[] ranks, int cars)