Easy Binary Search😉😉 || Beginner-friendly 🤗🤗|| 💯🚀🎯🔥💥
Approach
Function Definition:

The problem-solving function minCapability is defined inside a class named Solution.
This function receives two arguments:
nums:

# Approach
<!-- Describe your approach to solving the problem. -->
1. **Function Definition**:
- The problem-solving function minCapability is defined inside a class named Solution.
- This function receives two arguments:
nums: A vector representing the money in each house.
- k: The minimum number of houses the robber needs to rob.

2. **Initialize Binary Search Range**:
- The binary search operates on the range of possible maximum amounts the robber could steal from any house.
- The lower bound (left) is set to the smallest amount in nums.
- The upper bound (right) is set to the largest amount in nums.
3. **Binary Search Loop**:
- We perform a binary search to find the smallest possible maximum amount (maxMoney) the robber can steal while still being able to rob at least k houses.
- The loop continues as long as left is less than right.
- At each step, we calculate the midpoint (mid) of the current search range (left and right).
4. **Check Feasibility Using Greedy Approach**:
- For the current midpoint mid, check if it is possible to rob at least k houses with a "maximum money" of mid using a greedy approach.
- If it's possible (i.e., we can rob at least k houses), then the answer might be smaller, so adjust the upper bound (right) to mid.
- If it's not possible, increase the lower bound (left) to mid + 1.
5. **Final Result**:
- Once the binary search converges, the value of left will represent the smallest possible "maximum capability" the robber can have to rob at least k houses.
- This value is returned as the result.
6. **Helper Function (Greedy Selection)**:
- A helper function is defined to check if it's possible to rob at least k houses under a given maximum money (maxMoney).
- The helper function iterates through the nums array, and using a greedy approach, it selects houses to rob, ensuring no two adjacent houses are robbed.
- If the robber can rob at least k houses, the function returns true; otherwise, it returns false.

# Complexity
- Time complexity: O(n * log(max(nums) - min(nums)))
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

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

# Code
```cpp []
class Solution {
public:
    // Helper function to check if it's possible to rob at least k houses with max money limit
    bool canRobAtLeastKHouses(const vector<int>& nums, int k, int maxMoney) {
        int count = 0;
        int i = 0;

        // Greedily pick houses with money <= maxMoney and skip adjacent houses
        while (i < nums.size()) {
            if (nums[i] <= maxMoney) {
                count++;  // Rob this house
                i += 2;   // Skip the next house to avoid robbing adjacent houses
            } else {
                i++;  // Skip this house
            }
        }

        return count >= k;  // Return true if we have robbed at least k houses
    }

    int minCapability(vector<int>& nums, int k) {
        int left = *min_element(nums.begin(), nums.end());  // Minimum value in nums
        int right = *max_element(nums.begin(), nums.end()); // Maximum value in nums

        // Binary search for the minimum capability
        while (left < right) {
            int mid = left + (right - left) / 2;
            
            // Check if it's possible to rob at least k houses with max money <= mid
            if (canRobAtLeastKHouses(nums, k, mid)) {
                right = mid;  // Try smaller capabilities
            } else {
                left = mid + 1;  // Try larger capabilities
            }
        }

        return left;  // The smallest capability that works
    }
};

```
['C++']