Skip to content

Commit af40069

Browse files
author
deepshekhardas
committed
fix: add negative input validation to radix_sort
1 parent c0db072 commit af40069

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

sorts/radix_sort.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ def radix_sort(list_of_ints: list[int]) -> list[int]:
2121
True
2222
>>> radix_sort([1,100,10,1000]) == sorted([1,100,10,1000])
2323
True
24+
>>> radix_sort([-1, 0, 1])
25+
Traceback (most recent call last):
26+
...
27+
ValueError: radix_sort does not support negative numbers
2428
"""
29+
if any(i < 0 for i in list_of_ints):
30+
raise ValueError("radix_sort does not support negative numbers")
2531
placement = 1
2632
max_digit = max(list_of_ints)
2733
while placement <= max_digit:

0 commit comments

Comments
 (0)