Simple Solution using Binary Search
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python []
class Solution(object):
    def repairCars(self, ranks, cars):
        """
        :type ranks: List[int]
        :type cars: int
        :rtype: int
        """
        def check(ranks,n,time):
            total=0
            c=0
            for i in ranks:
                c=int(sqrt(time/i))
                total+=c
            if total>=n:
                return True
            else:
                return False
        low=min(ranks)
        high=max(ranks)*cars*cars
        while low<high:
            mid=(low+high)//2
            if check(ranks,cars,mid):
                high=mid
            else:
                low=mid+1
        return low


        
```
```Java []
import java.util.*;

class Solution {
    public int repairCars(int[] ranks, int cars) {
        int low = Arrays.stream(ranks).min().getAsInt();  // Minimum rank
        int high = Arrays.stream(ranks).max().getAsInt() * cars * cars;  // Upper bound
        
        while (low < high) {
            int mid = (low + high) / 2;
            if (canRepairInTime(ranks, cars, mid)) {
                high = mid;  // Try a smaller time
            } else {
                low = mid + 1;  // Increase time
            }
        }
        return low;
    }

    private boolean canRepairInTime(int[] ranks, int n, int time) {
        int total = 0;
        for (int rank : ranks) {
            int c = (int) Math.sqrt(time / rank);  // Solving x^2 * rank ≤ time
            total += c;
            if (total >= n) return true;  // If we can repair enough cars, return true
        }
        return false;
    }


        
```

```C++ []
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

class Solution {
public:
    bool canRepairInTime(vector<int>& ranks, int n, int time) {
        int total = 0;
        for (int rank : ranks) {
            int c = (int)sqrt(time / rank);  // Calculate max cars a mechanic can repair in given time
            total += c;
            if (total >= n) return true;  // If we can repair enough cars, return true
        }
        return false;
    }

    int repairCars(vector<int>& ranks, int cars) {
        int low = *min_element(ranks.begin(), ranks.end());  // Minimum rank
        int high = *max_element(ranks.begin(), ranks.end()) * cars * cars;  // Upper bound
        
        while (low < high) {
            int mid = (low + high) / 2;
            if (canRepairInTime(ranks, cars, mid)) {
                high = mid;  // Try a smaller time
            } else {
                low = mid + 1;  // Increase time
            }
        }
        return low;
    }
};
```

['Array', 'Binary Search', 'Python', 'C++', 'Java', 'Python3']