1
class Solution {
2
public int peakIndexInMountainArray(int[] arr) {
3

4
int start = 0;
5
int end = arr.length - 1;
6

7
while (start < end) {
8
int mid = start + (end - start) / 2;
9
// if mid < mid next
10
if (arr[mid] < arr[mid + 1]) {
11
start = mid + 1;
12
}
13
// otherwise it can either peak element or greater element
14
else {
15
end = mid;
16
}
17
}
18
return start; // or we can return end also, bcz both will be on same value at the time, that's
19
// why loop breaks here.
20
}
21
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0