From e10990844d0095874d034f7e793e5222fa19a8fe Mon Sep 17 00:00:00 2001 From: Nisarg Date: Wed, 12 Nov 2025 01:55:00 +0530 Subject: [PATCH 1/5] logical change in binary search's bisect left and right's "hi" limit --- 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..16ff85df5d68 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 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 while lo < hi: mid = lo + (hi - lo) // 2 From c9679e39becef9308e8a5cf921973738121c95ee Mon Sep 17 00:00:00 2001 From: Nisarg Date: Wed, 12 Nov 2025 02:29:40 +0530 Subject: [PATCH 2/5] adding the comment about negative indexing for hi --- 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 16ff85df5d68..81192817a1bf 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 + hi = len(sorted_collection)-hi #in case of usage of negative indexing 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 + hi = len(sorted_collection)-hi #in case of usage of negative indexing for hi while lo < hi: mid = lo + (hi - lo) // 2 From 695d4047757f8f7cde381bf1ccd44fdea1ad3d0c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 11 Nov 2025 21:03:58 +0000 Subject: [PATCH 3/5] [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 81192817a1bf..9b6cecc8a097 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 #in case of usage of negative indexing for hi + hi = len(sorted_collection) - hi # in case of usage of negative indexing 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 #in case of usage of negative indexing for hi + hi = len(sorted_collection) - hi # in case of usage of negative indexing for hi while lo < hi: mid = lo + (hi - lo) // 2 From c9d7c0217e434443bae37a33a297046308d1c213 Mon Sep 17 00:00:00 2001 From: Nisarg Date: Wed, 12 Nov 2025 03:02:03 +0530 Subject: [PATCH 4/5] logical error solving in the binary_search bisecgt_left's hi parameter --- 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 81192817a1bf..137e7d91b1a2 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 #in case of usage of negative indexing for hi + hi = len(sorted_collection)+hi #in case of usage of negative indexing 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 #in case of usage of negative indexing for hi + hi = len(sorted_collection)+hi #in case of usage of negative indexing for hi while lo < hi: mid = lo + (hi - lo) // 2 From f40e7638328e5844f7385eb1708371956177ce1d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 11 Nov 2025 21:37:31 +0000 Subject: [PATCH 5/5] [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 137e7d91b1a2..a88b6603d9be 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 #in case of usage of negative indexing for hi + hi = len(sorted_collection) + hi # in case of usage of negative indexing 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 #in case of usage of negative indexing for hi + hi = len(sorted_collection) + hi # in case of usage of negative indexing for hi while lo < hi: mid = lo + (hi - lo) // 2