Binary Search on Answer Technique
IntuitionWhenever we see in the question that we haave to calculate some minimum out of maximums or some maximum out of minimums we get to know that int this pr
# Intuition
Whenever we see in the question that we haave to calculate some minimum out of maximums or some maximum out of minimums we get to know that int this problem we have to apply binary search in answer.

# Approach
We need to find the minimum capability mid such that we can rob at least k houses while ensuring no two consecutive houses are robbed.

Key Observations:
Binary Search on Capability (mid)

We set mid as the maximum amount the thief can rob at any house.

The goal is to minimize mid while still robbing at least k houses.

Checking Feasibility (isPossible Function)

We iterate through nums and greedily pick houses where nums[i] ≤ mid, ensuring we skip the next house (i++) to maintain the no-consecutive rule.

If we successfully rob at least k houses, we try a lower mid, else we increase it.

Binary Search Execution:

1. Search Space (l, r): Minimum and maximum values in nums.
2. Mid Calculation: (l + r) / 2
3. Adjustment: If mid is feasible, we decrease r to find a smaller  valid capability; otherwise, we increase l.

# Complexity
Binary Search Complexity: 𝑂(log 𝑀) where M is the range of nums.

Feasibility Check (isPossible) Complexity: O(N) for each binary search step.

Overall Time Complexity: O(NlogM), efficient for large inputs.

Space Complexity: O(1) as only a few integer variables are used.

# Code
```java []
class Solution {
    public boolean isPossible(int[] nums, int mid, int k){
        int house = 0;
        for(int i = 0; i < nums.length; i++){
            if(nums[i] <= mid){
                house++;
                i++;
            }
        }

        return house >= k;
    }

    public int minCapability(int[] nums, int k) {
        int n = nums.length;

        int l = Arrays.stream(nums).min().getAsInt();
        int r = Arrays.stream(nums).max().getAsInt();

        int result = r;

        while(l <= r){
            int mid = l + (r - l) / 2;

            if(isPossible(nums, mid, k)){
                result = mid;
                r = mid - 1;
            } else {
                l = mid + 1;
            }
        }

        return result;
    }
}
```
['Java']