We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 9df5fb9 + 17324b2 commit 87e54bcCopy full SHA for 87e54bc
lectures/10-binary search/code/src/com/kunal/RBS.java
@@ -85,13 +85,13 @@ static int findPivotWithDuplicates(int[] arr) {
85
// skip the duplicates
86
// NOTE: what if these elements at start and end were the pivot??
87
// check if start is pivot
88
- if (arr[start] > arr[start + 1]) {
+ if (start < end && arr[start] > arr[start + 1]) {
89
return start;
90
}
91
start++;
92
93
// check whether end is pivot
94
- if (arr[end] < arr[end - 1]) {
+ if (end > start && arr[end] < arr[end - 1]) {
95
return end - 1;
96
97
end--;
0 commit comments