Skip to content

Commit 00fab97

Browse files
authored
Fix exponential search for empty collections (#15362)
Co-authored-by: = <=>
1 parent eb06d0d commit 00fab97

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

searches/exponential_search.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ def exponential_search(sorted_collection: list[int], item: int) -> int:
8585
if list(sorted_collection) != sorted(sorted_collection):
8686
raise ValueError("sorted_collection must be sorted in ascending order")
8787

88+
if not sorted_collection:
89+
return -1
8890
if sorted_collection[0] == item:
8991
return 0
9092

0 commit comments

Comments
 (0)