Peak of Mountain Array
MediumP2Coding
arr is a mountain array: it strictly increases up to a single peak and then strictly decreases. Return the index of the peak element.
Your solution must run in O(log n) time.
Example 1
- Input
- arr = [0,2,5,3,1]
- Output
- 2
Example 2
- Input
- arr = [1,3,2]
- Output
- 1
Example 3
- Input
- arr = [0,10,5,2]
- Output
- 1
Constraints
- 3 <= arr.length <= 10^5
- 0 <= arr[i] <= 10^6
- arr is strictly increasing then strictly decreasing, with the peak neither first nor last
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 9. ⌘Enter runs, ⌘⇧Enter submits.