Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion searches/binary_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ def binary_search(sorted_collection: list[int], item: int) -> int:
>>> binary_search([0, 5, 7, 10, 15], 6)
-1
"""
if list(sorted_collection) != sorted(sorted_collection):
if any(
sorted_collection[i] > sorted_collection[i + 1]
for i in range(len(sorted_collection) - 1)
):
raise ValueError("sorted_collection must be sorted in ascending order")
left = 0
right = len(sorted_collection) - 1
Expand Down