Created
June 17, 2021 00:00
-
-
Save MLWhiz/9ecd4f067ae53e6e02dee28303d5e5ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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