You are given an integer mountain array `arr` of length n: the values strictly increase up to some peak and then strictly decrease. Return the index of the peak element. Your solution must run in O(log n) time.
You are given an integer mountain array arr of length n: the values strictly increase up to some peak and then strictly decrease. Return the index of the peak element. Your solution must run in O(log n) time.
Example 1:
Input: {"arr":[0,1,0]}
Output: 1
Constraints:
3≤arr.length≤105
0≤arr[i]≤106
arr is guaranteed to be a mountain array.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"arr":[0,1,0]}
The peak hides somewhere in indexes 0 to 2, so the search range starts as the whole mountain.