Problem
A mountain array strictly increases up to a single peak and then strictly decreases. It has at least three elements, and the peak is never at either end. Given a mountain array arr, return the index of the peak in O(log n) time.
Example 1
- Input
- arr = [0, 1, 0]
- Output
- 1
Example 2
- Input
- arr = [0, 2, 1, 0]
- Output
- 1
Example 3
- Input
- arr = [3, 4, 5, 1]
- Output
- 2
Constraints
3 <= arr.length <= 10^50 <= arr[i] <= 10^6arr is guaranteed to be a mountain array.