2594. Minimum Time to Repair Cars Medium
1/**
2 * [2594] Minimum Time to Repair Cars
3 *
4 * You are given an integer array ranks representing the ranks of some mechanics. <font face="monospace">ranksi</font> is the rank of the <font face="monospace">i^th</font> mechanic<font face="monospace">.</font> A mechanic with a rank r can repair <font face="monospace">n</font> cars in r * n^2 minutes.
5 * You are also given an integer cars representing the total number of cars waiting in the garage to be repaired.
6 * Return the minimum time taken to repair all the cars.
7 * Note: All the mechanics can repair the cars simultaneously.
8 *
9 * <strong class="example">Example 1:
10 *
11 * Input: ranks = [4,2,3,1], cars = 10
12 * Output: 16
13 * Explanation:
14 * - The first mechanic will repair two cars. The time required is 4 * 2 * 2 = 16 minutes.
15 * - The second mechanic will repair two cars. The time required is 2 * 2 * 2 = 8 minutes.
16 * - The third mechanic will repair two cars. The time required is 3 * 2 * 2 = 12 minutes.
17 * - The fourth mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.
18 * It can be proved that the cars cannot be repaired in less than 16 minutes.
19 *
20 * <strong class="example">Example 2:
21 *
22 * Input: ranks = [5,1,8], cars = 6
23 * Output: 16
24 * Explanation:
25 * - The first mechanic will repair one car. The time required is 5 * 1 * 1 = 5 minutes.
26 * - The second mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.
27 * - The third mechanic will repair one car. The time required is 8 * 1 * 1 = 8 minutes.
28 * It can be proved that the cars cannot be repaired in less than 16 minutes.
29 *
30 *
31 * Constraints:
32 *
33 * 1 <= ranks.length <= 10^5
34 * 1 <= ranks[i] <= 100
35 * 1 <= cars <= 10^6
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/minimum-time-to-repair-cars/
41// discuss: https://leetcode.com/problems/minimum-time-to-repair-cars/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn repair_cars(ranks: Vec<i32>, cars: i32) -> i64 {
47
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_2594() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.