Peak Index in a Mountain Array
Binary search for the first downhill step of a mountain array.
The problem
Implement Solution.peakIndexInMountainArray(arr). arr is a mountain: it strictly increases up to one peak and then strictly decreases, and the peak is never the first or last element. Return the index of the peak. Your solution must run in O(log n) time. For example, [0, 2, 1, 0] returns 1. 3 <= len(arr) <= 100000.
Starter code
class Solution:
def peakIndexInMountainArray(self, arr):
passPublic examples
arr = [0, 2, 1, 0]gives1arr = [0, 6, 5, 4, 3, 2, 1]gives1arr = [0, 1, 2, 3, 4, 8, 6, 2, 1]gives5
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
