From af40069954d602591bc1941731b80a9599f4c4a5 Mon Sep 17 00:00:00 2001 From: deepshekhardas Date: Mon, 20 Jul 2026 12:46:09 +0530 Subject: [PATCH] fix: add negative input validation to radix_sort --- sorts/radix_sort.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sorts/radix_sort.py b/sorts/radix_sort.py index 1dbf5fbd1365..6374d513268b 100644 --- a/sorts/radix_sort.py +++ b/sorts/radix_sort.py @@ -21,7 +21,13 @@ def radix_sort(list_of_ints: list[int]) -> list[int]: True >>> radix_sort([1,100,10,1000]) == sorted([1,100,10,1000]) True + >>> radix_sort([-1, 0, 1]) + Traceback (most recent call last): + ... + ValueError: radix_sort does not support negative numbers """ + if any(i < 0 for i in list_of_ints): + raise ValueError("radix_sort does not support negative numbers") placement = 1 max_digit = max(list_of_ints) while placement <= max_digit: