A mountain array is one that strictly climbs up to a single summit and then strictly slides back down. Given such an array, report the index of that summit, the position where the values stop increasing and begin decreasing.
Since the shape guarantees exactly one peak and no flat stretches, you can steer toward it by checking the slope at the midpoint rather than examining every entry.
Example 1
Input: arr = [0,2,1,0]
Output: 1
Values rise to 2 at index 1 and fall afterward, so the peak index is 1.
Example 2
Input: arr = [0,10,5,2]
Output: 1
The largest value 10 sits at index 1, which is the summit.
Constraints
3 ≤ arr.length ≤ 10^50 ≤ arr[i] ≤ 10^6arr is guaranteed to be a valid mountain arraySee the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI