1
var peakIndexInMountainArray = function (arr) {
2
//lets assume we have peak it divides array in two parts
3
// first part is increasing order , second part is decreasing
4
// when we find the middle we'll compare arr[middle] > arr[middle+1], it means
5
//we can only find max in first part of arr (increasing part) else second part.
6
//there will be point where start === end that is our peak
7
let start = 0;
8
let end = arr.length - 1;
9
while (start < end) {
10
let mid = parseInt(start + (end - start) / 2);
11
if (arr[mid] > arr[mid + 1]) {
12
end = mid;
13
} else {
14
start = mid + 1;
15
}
16
}
17

18
return start;
19
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0