From 4d655584ac429c01615a62881d56e44504aac94b Mon Sep 17 00:00:00 2001 From: Nisarg Date: Wed, 12 Nov 2025 11:59:31 +0530 Subject: [PATCH 1/2] fixed logical error in parameter "hi" the bisect functions of the binary search --- searches/binary_search.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/searches/binary_search.py b/searches/binary_search.py index 2e66b672d5b4..8142817a1b1b 100644 --- a/searches/binary_search.py +++ b/searches/binary_search.py @@ -45,7 +45,7 @@ def bisect_left( 2 """ if hi < 0: - hi = len(sorted_collection) + hi = len(sorted_collection)+hi+1 #in case of negetive indexing used for hi while lo < hi: mid = lo + (hi - lo) // 2 @@ -86,7 +86,7 @@ def bisect_right( 2 """ if hi < 0: - hi = len(sorted_collection) + hi = len(sorted_collection)+hi+1 #in case of negetive indexing used for hi while lo < hi: mid = lo + (hi - lo) // 2 From 10d86d2db984cae355ecb26a9986c993248df8e6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 12 Nov 2025 06:33:54 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- searches/binary_search.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/searches/binary_search.py b/searches/binary_search.py index 8142817a1b1b..bd8071ba9c68 100644 --- a/searches/binary_search.py +++ b/searches/binary_search.py @@ -45,7 +45,7 @@ def bisect_left( 2 """ if hi < 0: - hi = len(sorted_collection)+hi+1 #in case of negetive indexing used for hi + hi = len(sorted_collection) + hi + 1 # in case of negetive indexing used for hi while lo < hi: mid = lo + (hi - lo) // 2 @@ -86,7 +86,7 @@ def bisect_right( 2 """ if hi < 0: - hi = len(sorted_collection)+hi+1 #in case of negetive indexing used for hi + hi = len(sorted_collection) + hi + 1 # in case of negetive indexing used for hi while lo < hi: mid = lo + (hi - lo) // 2