-
-
Notifications
You must be signed in to change notification settings - Fork 48.7k
Meta Binary Search #12197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Meta Binary Search #12197
Changes from all commits
8790932
daf2bea
dacde35
94d52ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
def meta_binary_search(arr, target): | ||
low = 0 | ||
high = len(arr) - 1 | ||
while low <= high: | ||
mid = (low + high) // 2 | ||
if arr[mid] == target: | ||
return mid | ||
elif arr[mid] < target: | ||
low = mid + 1 | ||
else: | ||
high = mid - 1 | ||
return -1 | ||
|
||
|
||
def main(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file Please provide return type hint for the function: |
||
arr = [2, 5, 8, 12, 16, 23, 38, 56, 72, 91] | ||
target = 23 | ||
result = meta_binary_search(arr, target) | ||
if result != -1: | ||
print("Element found at index: ", result) | ||
else: | ||
print("Element not found!") | ||
|
||
|
||
if __name__ == "main": | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file
searches/meta_binary_search.py
, please provide doctest for the functionmeta_binary_search
Please provide return type hint for the function:
meta_binary_search
. If the function does not return a value, please provide the type hint as:def function() -> None:
Please provide type hint for the parameter:
arr
Please provide type hint for the parameter:
target