JAVA SIMPLE SOLUTION (space complexity -O(1)) [Binary Search]
IntuitionUse binary search to minimize the maximum time required to repair all cars.Approach

Find the maximum rank:

The higher the rank, the slower the mechan
# Intuition
Use binary search to minimize the maximum time required to repair all cars.

# Approach
- Find the maximum rank:

    - The higher the rank, the slower the mechanic.
    - We find the highest rank to estimate the worst-case time needed.

- Use Binary Search on Time:

    - The minimum possible time is 1, and the maximum is maxRank × cars².
    - We search for the smallest time T where all cars can be repaired.

- Check if Time is Valid:

    - For a given T, check how many cars each mechanic can fix using:
            Cars fixed=𝑇/rank 
    - If the total cars repaired ≥ required cars, the time is valid

# Complexity
- Time complexity:
O(nlog(maxRank×cars^2))

- Space complexity:
O(1)

# Code
```java []
class Solution {
    public long repairCars(int[] ranks, int cars) {
        int maxRank=Integer.MIN_VALUE;
        for(int i=0;i<ranks.length;i++)
        {
            maxRank=Math.max(maxRank,ranks[i]);
        }
        long max = (long) maxRank * cars * cars;

        return bs(1,max,ranks,cars);
    }

    public long bs(long l, long r, int[] ranks, int cars)
    {
        
        long mid=(l+r)/2;

        if(l>=r)
        {
            return mid;
        }
        
        if(valid(mid,ranks,cars)==true)
        {
            return bs(l,mid,ranks,cars);
        }
        else
        {
            return bs(mid+1,r,ranks,cars);
        }
    }

    public boolean valid(long T,int[] ranks, int cars)
    {
        long sum=0;
        for(int i=0;i<ranks.length;i++)
        {
            sum=sum+(long)Math.sqrt(T/ranks[i]);
        }
        if(sum>=cars)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
```
['Java']