1
var validMountainArray = function (arr) {
2
let index = 0,
3
length = arr.length;
4
//find the peak
5
while (index < length && arr[index] < arr[index + 1]) index++;
6
//edge cases
7
if (index === 0 || index === length - 1) return false;
8
//check if starting from peak to end of arr is descending order
9

10
while (index < length && arr[index] > arr[index + 1]) index++;
11

12
return index === length - 1;
13
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0