Skip to content
Open
Changes from all 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
6 changes: 5 additions & 1 deletion searches/median_of_medians.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ def quick_select(arr: list, target: int) -> int:
3
>>> quick_select([3, 5, 7, 10, 2, 12], 3)
5
>>> quick_select([2, 4, 5, 7, 899, 54, 32], 0)
-1
>>> quick_select([2, 4, 5, 7, 899, 54, 32], -1)
-1
"""

# Invalid Input
if target > len(arr):
if target <= 0 or target > len(arr):
return -1

# x is the estimated pivot by median of medians algorithm
Expand Down
Loading