C# Solution for House Robber IV Problem
IntuitionThe problem requires selecting at least k houses to rob while ensuring no two adjacent houses are robbed. The goal is to minimize the worst-case amount
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem requires selecting at least k houses to rob while ensuring no two adjacent houses are robbed. The goal is to minimize the worst-case amount of money stolen from a single house in any valid selection.
•	Key Idea: If we fix a maximum allowed amount (capability), we can check whether we can rob at least k houses while ensuring no two adjacent houses are robbed.
•	Binary Search on Capability: We binary search over the range [min(nums), max(nums)] to find the smallest valid capability.

# Approach
<!-- Describe your approach to solving the problem. -->
1.	Define the Binary Search Range:
	•	left = min(nums), since the minimum possible capability is the smallest house value.
	•	right = max(nums), since the maximum possible capability is the largest house value.
2.	Perform Binary Search on capability:
	•	Find mid = (left + right) / 2, which represents a candidate capability.
	•	Check if it’s possible to rob at least k houses with a capability ≤ mid.
	•	If possible, try a lower capability (right = mid).
	•	Otherwise, increase capability (left = mid + 1).
3.	Greedy Check (CanRobAtLeastK function):
	•	Iterate through nums, robbing a house only if its value is ≤ capability.
	•	Skip the next house (to ensure no adjacent houses are robbed).
	•	If at least k houses can be robbed, return true.
4.	Return the Minimum Valid capability.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
1.	Binary Search on capability:
	•	The range of capability is [min(nums), max(nums)], so the binary search takes: O(log(max(nums) - min(nums)))
	•	Since nums[i] can be up to 10^9, this results in at most O(log 10^9) = O(30) iterations.
2.	Greedy Check (CanRobAtLeastK function):
	•	Iterates through nums once, which takes O(n) time.
3.	Total Complexity:
	•	The binary search calls the greedy function at most O(30) times.
	•	Each call to the greedy function takes O(n).
	•	Final complexity: O(n log(max(nums) - min(nums)))
	•	Efficient for n ≤ 10^5.

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
•	O(1): We only use a few integer variables (left, right, mid, count, i).
•	No extra arrays or data structures are used.

# Code
```csharp []
public class Solution {
    public int MinCapability(int[] nums, int k) {
        int left = int.MaxValue, right = int.MinValue;

        foreach (int num in nums) {
            left = Math.Min(left, num);
            right = Math.Max(right, num);
        }

        while (left < right) {
            int mid = left + (right - left) / 2;
            if (CanRobAtLeastK(nums, k, mid)) {
                right = mid; 
            } else {
                left = mid + 1; 
            }
        }

        return left;
    }
    private bool CanRobAtLeastK(int[] nums, int k, int cap) {
        int count = 0;
        int i = 0;

        while (i < nums.Length) {
            if (nums[i] <= cap) {
                count++;
                i++; 
            }
            i++; 
        }

        return count >= k;
    }
}
```
['C#']