Mountain Peak Index
MediumAcc. 94.2%
+30 XP 12
Mountain Ascent
A mountain array strictly increases and then strictly decreases. Find the index of the highest point.
The Assignment
Your function receives arr.
- Use Binary Search.
- If
arr[mid] < arr[mid+1], the peak is on the right. - Else, the peak is this index or on the left.
- Print the final index.
01EXAMPLE 1
Input
[0, 10, 5, 2]Output
1Explanation: 10 is at index 1.
Constraints
- O(log n) time complexity.
ArraysSearching
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
arr[0,2,1,0]
Expected Output
1
Click RUN to test your solution