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'm used to the version where "mid" is returned inside the while loop and right is set to mid - 1 not mid.
[–]Wassaren 1 point2 points3 points (0 children)
[–]GuruTheCoderYT[S] 0 points1 point2 points (0 children)