Simple Binary search with explanation
Code


# Code
```java []
class Solution {
    public int minCapability(int[] nums, int k) {

        int left=0;
        int right=0;
        int result=0;
        // finding min and max element for binary search
        for(int num:nums)
        {
            left=Math.min(num,left);
            right=Math.max(num,right);
        }

        

        while(left<=right)
        {
            int houseRob=0;
            int mid=left+(right-left)/2;

            for(int i=0;i<nums.length;i++)
            {
                if(nums[i]<=mid)
                {
                    houseRob++;
                    i++;//to skip the adjacent houses

                }
                
            }
            if(houseRob>=k)
            {
                //if we can rob housesRob houses,check for lower values as well.
                result=mid;
                right=mid-1;
            }
            else
            {
                // if we cannot rob housesRob houses, move to higher values.
                
                left=mid+1;
            }
        }

        return result;

        
    }
}
```
['Java']