From 6a5ab6c5f9200d33948af40c672f6f8088dc0997 Mon Sep 17 00:00:00 2001 From: ferkans-amir Date: Mon, 27 Jul 2026 21:09:03 +0200 Subject: [PATCH] fix(sorts): raise ValueError on negative integers in radix_sort --- sorts/radix_sort.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sorts/radix_sort.py b/sorts/radix_sort.py index 1dbf5fbd1365..ec9979ea69df 100644 --- a/sorts/radix_sort.py +++ b/sorts/radix_sort.py @@ -19,9 +19,17 @@ def radix_sort(list_of_ints: list[int]) -> list[int]: True >>> radix_sort(list(range(14,-1,-1))) == sorted(range(15)) True - >>> radix_sort([1,100,10,1000]) == sorted([1,100,10,1000]) + >>> radix_sort([1, 100, 10, 1000]) == sorted([1, 100, 10, 1000]) True + >>> radix_sort([1, 3, -2, 4]) + Traceback (most recent call last): + ... + ValueError: radix_sort() only accepts non-negative integers """ + if any(i < 0 for i in list_of_ints): + raise ValueError("radix_sort() only accepts non-negative integers") + if not list_of_ints: + return [] placement = 1 max_digit = max(list_of_ints) while placement <= max_digit: