I don't get how this works. Could you please prove this? Thanks.
def binary_search(array) -> int:
def condition(value) -> bool:
pass
left, right = min(search_space), max(search_space) # could be [0, n], [1, n] etc. Depends on problem
while left < right:
mid = left + (right - left) // 2
if condition(mid):
right = mid
else:
left = mid + 1
return left
I believe you would benefit from reading/watching a video on BinarySearch https://www.youtube.com/watch?v=P3YID7liBug.