From 0cbc24dec70b64553511eb08d09e294c802705b0 Mon Sep 17 00:00:00 2001 From: Keerthi T N Date: Sun, 26 Jul 2026 20:58:14 +0530 Subject: [PATCH] Raise ValueError for negative inputs in radix_sort --- sorts/radix_sort.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sorts/radix_sort.py b/sorts/radix_sort.py index 1dbf5fbd1365..92794815c55d 100644 --- a/sorts/radix_sort.py +++ b/sorts/radix_sort.py @@ -21,7 +21,14 @@ 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, 3, -2, 4]) + Traceback (most recent call last): + ... + ValueError: negative integers are not supported """ + if any(i < 0 for i in list_of_ints): + raise ValueError("negative integers are not supported") + placement = 1 max_digit = max(list_of_ints) while placement <= max_digit: