Swift, easy efficient solution 🍎🚀🤟
IntuitionFor Binary search, we just need to figure out what should be range. That is min or max. Min can be 0 mins and max will be if the max rank mechanic will
# Intuition
For Binary search, we just need to figure out what should be range. That is min or max. Min can be 0 mins and max will be if the max rank mechanic will repair all the cars: ranks.max() * cars * cars.

The challenge is how we determine if x mins is enough for the cars. Think about if all the mechanic takes x mins, will the total cars be repaired?

# Approach
- If ranks is 1, all the cars needs to be repaired by one mechanic. Simply return ranks.max() * cars * cars
- Declare left and right as above
- If all the mechanic repair for x mins, will all the cars be repaired. If yes, we know it is possible.
- Since we need to find min possible, we perform binary search and keep on decreasing the range as per condition.
- Return left.

# Please Upvote if this helped 😊🤟 Happy Coding! 😀

# Complexity
- Time complexity:
O(nlog(max(r))), n is iteration for ranks, r is max time possible.

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

# Code
```swift []
import Swift
import Foundation

class Solution {
    func repairCars(_ ranks: [Int], _ cars: Int) -> Int {
        if ranks.count == 1 { return ranks[0]*cars*cars }
        var left = 0, right = (ranks.max() ?? 0) * cars * cars
        func repairPossible(_ mid: Int) -> Bool {
            var count = 0
            for rank in ranks {
                let nos = Int(sqrt(Double(mid/rank)))
                count += nos
            }
            return count >= cars
        }
        while left < right {
            let mid = left + (right-left)/2
            if repairPossible(mid) {
                right = mid
            } else {
                left = mid + 1
            }
        }
        return left
    }
}
```
['Swift']