✅Binary Search 🔥| Visualization ✨| Math | Python | C++ | Java ✨
Approach
Complexity

Time complexity:   O(log(max(nums)).n)


Space complexity:  O(1)

Code

# Approach
![image.png](https://assets.leetcode.com/users/images/889befcf-6bca-436f-a944-d0168b6b2123_1742011527.9166548.png)
![image.png](https://assets.leetcode.com/users/images/681db22e-19bc-4f9b-926c-2af5e2fc1c8f_1742011548.8817725.png)



# Complexity
- Time complexity:   $$O(log(max(nums)).n)$$

- Space complexity:  $$O(1)$$ 

# Code
```python []
class Solution(object):
    def canRob(self, nums, mid, k):
        count = 0
        n = len(nums)
        i = 0
        while i < n:
            if nums[i] <= mid:
                count += 1
                i += 1
            i += 1
        return count >= k

    def minCapability(self, nums, k):
        left, right = 1, max(nums)
        ans = right
        while left <= right:
            mid = (left + right) // 2
            if self.canRob(nums, mid, k):
                ans = mid
                right = mid - 1
            else:
                left = mid + 1
        return ans

```
```C++ []
class Solution {
public:
    bool canRob(vector<int>& nums, int mid, int k) {
        int count = 0, n = nums.size();
        for (int i = 0; i < n; i++) {
            if (nums[i] <= mid) {
                count++;
                i++;
            }
        }
        return count >= k;
    }

    int minCapability(vector<int>& nums, int k) {
        int left = 1, right = *max_element(nums.begin(), nums.end()), ans = right;
        while (left <= right) {
            int mid = (left + right) / 2;
            if (canRob(nums, mid, k)) {
                ans = mid;
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return ans;
    }
};


```
```Java []
class Solution {
    public boolean canRob(int[] nums, int mid, int k) {
        int count = 0, n = nums.length;
        for (int i = 0; i < n; i++) {
            if (nums[i] <= mid) {
                count++;
                i++;
            }
        }
        return count >= k;
    }

    public int minCapability(int[] nums, int k) {
        int left = 1, right = Arrays.stream(nums).max().getAsInt(), ans = right;
        while (left <= right) {
            int mid = (left + right) / 2;
            if (canRob(nums, mid, k)) {
                ans = mid;
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return ans;
    }
}


```
![image.png](https://assets.leetcode.com/users/images/31c52833-a0c0-4659-9cd9-299eeab9a492_1742011668.2264543.png)

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