Skip to content

Instantly share code, notes, and snippets.

@MLWhiz
Created June 17, 2021 00:00
Show Gist options
  • Save MLWhiz/9ecd4f067ae53e6e02dee28303d5e5ae to your computer and use it in GitHub Desktop.
Save MLWhiz/9ecd4f067ae53e6e02dee28303d5e5ae to your computer and use it in GitHub Desktop.
def binary_search(array):
def condition(value):
pass
# could be [0, n], [1, n] etc. Depends on problem
left, right = min(search_space), max(search_space)
while left < right:
mid = left + (right - left) // 2
if condition(mid):
right = mid
else:
left = mid + 1
return left
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment