Well Explained Java Solution with intuition!!!
IntuitionThe problem requires us to determine the minimum capability of the robber, which is the maximum money he steals from a single house while ensuring that
# Intuition
The problem requires us to determine the **minimum capability** of the robber, which is the maximum money he steals from a single house while ensuring that he robs at least `k` houses and does not rob adjacent houses.

Instead of checking all subsets of houses (which would be inefficient), we use **binary search** on the capability value to efficiently determine the minimum possible capability that allows robbing at least `k` houses.

# Approach
1. **Find the Range of Capabilities**:  
   - The minimum possible capability (`l`) is the **smallest** house value (`min(nums)`).  
   - The maximum possible capability (`r`) is the **largest** house value (`max(nums)`).  
   - Our answer must lie within this range.

2. **Binary Search on Capability**:
   - We use binary search to find the minimum capability `mid` that allows robbing at least `k` houses.
   - If it's **possible** to rob at least `k` houses with `mid` as the capability, update `ans = mid` and try to find a smaller value (`r = mid - 1`).
   - Otherwise, increase the lower bound (`l = mid + 1`).

3. **Handling Cases Where `mid` is Not in `nums`**:
   - Since `mid` is computed as `(l + r) / 2`, it **might not be an actual value in `nums`**.
   - If `mid` is not in `nums`, our binary search will automatically adjust and continue reducing `mid` until it finds the **smallest valid element** that allows robbing at least `k` houses.
   - This ensures that we get the minimum possible capability.

4. **Check Feasibility (`isPossible` function)**:
   - Iterate through `nums` and rob houses **greedily** while ensuring no adjacent houses are robbed.
   - If we can rob at least `k` houses without exceeding `mid` as the max robbed value, return `true`.

This **binary search approach** efficiently narrows down the minimum possible capability in **logarithmic time**, rather than checking all possibilities.

# Complexity
- **Time complexity:**  
  - **Binary search** runs in **$$O(\log M)$$**, where `M` is the range of house values (`max(nums) - min(nums)`).
  - The `isPossible` function runs in **$$O(n)$$** for each binary search step.
  - Thus, the total complexity is **$$O(n \log M)$$**.

- **Space complexity:**  
  - We use only a few integer variables, so the space complexity is **$$O(1)$$** (constant space).

# Code
```java
class Solution {
    public int minCapability(int[] nums, int k) {
        int minVal = Integer.MAX_VALUE, maxVal = Integer.MIN_VALUE;
        
        // Find min and max values in nums
        for (int num : nums) {
            minVal = Math.min(minVal, num);
            maxVal = Math.max(maxVal, num);
        }
        
        int l = minVal, r = maxVal, mid, ans = 0;
        
        // Binary search for the minimum capability
        while (l <= r) {
            mid = (l + r) / 2;
            if (isPossible(nums, k, mid)) {
                ans = mid;  // Update answer
                r = mid - 1; // Try to find a smaller capability
            } else {
                l = mid + 1;
            }
        }
        
        return ans;
    }
    
    // Function to check if we can rob at least k houses with capability v
    public boolean isPossible(int[] nums, int k, int v) {
        int i = 0;
        
        while (i < nums.length) {
            if (nums[i] <= v) {  // If house can be robbed under current capability
                k--;  // Decrease required house count
                ++i;  // Skip next house to ensure non-adjacency
            }
            if (k == 0) {
                return true;  // Successfully robbed at least k houses
            }
            ++i;
        }
        
        return false; // Not enough houses robbed
    }
}

['Binary Search', 'Java']