easy to understand🥳 || simple code 😊 || C++✅ || Java ✅ ||Python ✅
Intuition
Binary Search
ApproachComplexity
Time complexity:O(nlogm)

Space complexity:O(1)
Code
^_^
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
- Binary Search
# Approach
<!-- Describe your approach to solving the problem. -->
![2594.jpg](https://assets.leetcode.com/users/images/dbbc7eb2-7bc3-4400-90b9-541bdf509c30_1742085936.538902.jpeg)

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

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

# Code
```cpp []
class Solution {
public:
    bool solve(long long res,vector<int>& ranks, int cars){
        long long cnt=0;
        for(int i=0;i<ranks.size();i++){
            cnt+=sqrt((res*1.0)/ranks[i]);
        }

        return cnt>=cars*1LL;
    }
    long long repairCars(vector<int>& ranks, int cars) {

        long long low=1;
        long long high=*max_element(ranks.begin(),ranks.end())*1LL*cars*cars;

        long long ans=high;

        while(low<=high){
            long long mid=(low+high)/2;
            if(solve(mid,ranks,cars)){
                ans=mid;
                high=mid-1;
            }else{
                low=mid+1;
            }
        }
        return ans;
        
    }
};
```
```java []
import java.util.*;

class Solution {
    public boolean solve(long res, int[] ranks, int cars) {
        long cnt = 0;
        for (int rank : ranks) {
            cnt += Math.sqrt((res * 1.0) / rank);
        }
        return cnt >= (long) cars;
    }

    public long repairCars(int[] ranks, int cars) {
        long low = 1;
        long high = (long) Arrays.stream(ranks).max().getAsInt() * cars * cars;
        long ans = high;

        while (low <= high) {
            long mid = (low + high) / 2;
            if (solve(mid, ranks, cars)) {
                ans = mid;
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }
        return ans;
    }
}
```
```python []
import math

class Solution:
    def solve(self, res, ranks, cars):
        cnt = 0
        for rank in ranks:
            cnt += int(math.sqrt(res / rank))
        return cnt >= cars

    def repairCars(self, ranks, cars):
        low, high = 1, max(ranks) * cars * cars
        ans = high
        while low <= high:
            mid = (low + high) // 2
            if self.solve(mid, ranks, cars):
                ans = mid
                high = mid - 1
            else:
                low = mid + 1
        return ans

```
![please-upvote-please.jpg](https://assets.leetcode.com/users/images/b5b68180-cbd6-4833-a00b-edca168acfd8_1742086203.7158384.jpeg)
^_^

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