Skip to content

Commit 87e54bc

Browse files
Merge pull request kunal-kushwaha#141 from Deveshb15/main
Fixed index out of bound error in rotated binary search with duplicates
2 parents 9df5fb9 + 17324b2 commit 87e54bc

File tree

1 file changed

+2
-2
lines changed
  • lectures/10-binary search/code/src/com/kunal

1 file changed

+2
-2
lines changed

lectures/10-binary search/code/src/com/kunal/RBS.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ static int findPivotWithDuplicates(int[] arr) {
8585
// skip the duplicates
8686
// NOTE: what if these elements at start and end were the pivot??
8787
// check if start is pivot
88-
if (arr[start] > arr[start + 1]) {
88+
if (start < end && arr[start] > arr[start + 1]) {
8989
return start;
9090
}
9191
start++;
9292

9393
// check whether end is pivot
94-
if (arr[end] < arr[end - 1]) {
94+
if (end > start && arr[end] < arr[end - 1]) {
9595
return end - 1;
9696
}
9797
end--;

0 commit comments

Comments
 (0)