left
to 1 and right
to the maximum value in nums
(1e9).mid
as the average of left
and right
.
b. Use a greedy approach to count the number of houses that can be robbed with capability mid
without robbing adjacent houses.
c. If the count is at least k
, update right
to mid
. Otherwise, update left
to mid + 1
.left
is equal to right
, which will be the minimum capability required.left
as the answer.