From dcc1d8870242ed4618d368ef9dc10693eb1f9b59 Mon Sep 17 00:00:00 2001 From: deepshekhardas Date: Fri, 21 Aug 2026 10:49:48 +0530 Subject: [PATCH] fix(radix_sort): raise ValueError for negative inputs Fixes #14950 --- sorts/radix_sort.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sorts/radix_sort.py b/sorts/radix_sort.py index 1dbf5fbd1365..23f19f48fb68 100644 --- a/sorts/radix_sort.py +++ b/sorts/radix_sort.py @@ -22,8 +22,11 @@ def radix_sort(list_of_ints: list[int]) -> list[int]: >>> radix_sort([1,100,10,1000]) == sorted([1,100,10,1000]) True """ + if any(x < 0 for x in list_of_ints): + raise ValueError("radix_sort only supports non-negative integers") + placement = 1 - max_digit = max(list_of_ints) + max_digit = max(list_of_ints) if list_of_ints else 0 while placement <= max_digit: # declare and initialize empty buckets buckets: list[list] = [[] for _ in range(RADIX)]