Peak Index in a Mountain Array
Problem statement
A mountain array strictly increases to one peak and then strictly decreases. Return the zero-based index of its peak.
Function
peakIndexInMountainArray(arr: int[]) → intExamples
Example 1
arr = [0,1,0]return = 1The middle element is the peak.
Example 2
arr = [0,2,5,3,1]return = 2The sequence changes slope at index two.
Example 3
arr = [-5,-2,4,3]return = 2Negative values do not change the slope logic.
Constraints
3 <= arr.length <= 100000.-10^9 <= arr[i] <= 10^9.- There is exactly one peak and it is not an endpoint.