Simple Binary Search & Greedy | Cpp | java | Python | O(n log(*max_ele) | O(1) ✨😎
Intuition
The robber wants to steal from at least k non-adjacent houses.
The capability is the maximum amount of money stolen from any single house in a chosen
# Intuition
- The robber wants to steal from at least k non-adjacent houses.
- The capability is the maximum amount of money stolen from any single house in a chosen set.
- The goal is to minimize this capability while ensuring at least k houses are robbed.
<!-- Describe your first thoughts on how to solve this problem. -->

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

# Complexity
- Time complexity: O(N log M)
M = MAX_Element In Nums
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

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

# Code
```java []
class Solution {
    private boolean canRobAtLeastK(int[] nums, int mid, int k) {
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] <= mid) {
                count++;
                i++; // Skip the next house to maintain non-adjacency
            }
        }
        return count >= k;
    }

    public int minCapability(int[] nums, int k) {
        int low = Arrays.stream(nums).min().getAsInt();
        int high = Arrays.stream(nums).max().getAsInt();

        while (low <= high) {
            int mid = (low + high) / 2;
            if (canRobAtLeastK(nums, mid, k))
                high = mid - 1; // Try for a lower capability
            else
                low = mid + 1; // Increase the capability
        }
        return low;
    }
}
```
```python3 []
class Solution:
    def canRobAtLeastK(self, nums: List[int], mid: int, k: int) -> bool:
        count = 0
        i = 0
        while i < len(nums):
            if nums[i] <= mid:
                count += 1
                i += 1  # Skip next house to maintain non-adjacency
            i += 1
        return count >= k

    def minCapability(self, nums: List[int], k: int) -> int:
        low, high = min(nums), max(nums)

        while low <= high:
            mid = (low + high) // 2
            if self.canRobAtLeastK(nums, mid, k):
                high = mid - 1  # Try a smaller capability
            else:
                low = mid + 1  # Increase capability

        return low

```

```cpp []
#include <bits/stdc++.h>
class Solution {
    bool func(vector<int>& nums, int mid, int k) {
        int no_house = 0;
        for (int i = 0; i < nums.size(); i++) {
            if (nums[i] <= mid) {
                no_house++;
                i++;  // Skip next house to maintain non-adjacency
            }
        }
        return no_house >= k;
    }

public:
    int minCapability(vector<int>& nums, int k) {
        int low = *min_element(nums.begin(), nums.end());
        int high = *max_element(nums.begin(), nums.end());

        while (low <= high) {
            int mid = (low + high) / 2;
            if (func(nums, mid, k)) 
                high = mid - 1;
            else 
                low = mid + 1;
        }
        return low;
    }
};
```
['Array', 'Binary Search', 'C++', 'Java', 'Python3']