15% off all plans & roadmaps Use code
See plansLeetCode 852 · Solution & editorial
You are given an integer mountain array arr of length n where the values increase to a peak element and then decrease.
Peak Index in a Mountain Array is a Binary Search Patterns problem, in the Find Min/Max in Rotated Sorted Array subpattern. The pattern covers standard binary search, rotated arrays, first/last occurrence, and search on answer space
Master binary search in rotated sorted arrays. Find minimum, search elements, and handle duplicates.
The reference solution runs in O(logn) time and O(1) space.
Peak Index in a Mountain Array has been reported in interviews at Bloomberg, Yahoo.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Peak Index in a Mountain Array is a Binary Search Patterns problem, in the Find Min/Max in Rotated Sorted Array subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.