From cb21d7dc51338c673a75100be1127f28ff544224 Mon Sep 17 00:00:00 2001 From: devam007 Date: Fri, 23 Oct 2026 20:57:24 +0530 Subject: [PATCH] fix: reject negative bisect lower bounds --- searches/binary_search.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/searches/binary_search.py b/searches/binary_search.py index 6bab1c1cbdc5..11a51e38c7eb 100644 --- a/searches/binary_search.py +++ b/searches/binary_search.py @@ -49,6 +49,9 @@ def bisect_left( >>> bisect_left([1, 2, 2, 2, 4], 2) 1 """ + if lo < 0: + raise ValueError("lo must be non-negative") + if hi < 0: hi = len(sorted_collection) @@ -96,6 +99,9 @@ def bisect_right( >>> bisect_right([1, 2, 2, 2, 4], 2) 4 """ + if lo < 0: + raise ValueError("lo must be non-negative") + if hi < 0: hi = len(sorted_collection)