Back to problems Sign in to unlock
Leetcode
Medium
Arrays
Binary Search
Google
Peak Index In A Mountain Array
Find the index of the peak element in a mountain array.
Acceptance 90%
Problem Statement
Problem
You are given a mountain array arr of length n.
A mountain array has the following properties:
n >= 3- There exists an index
peaksuch that:arr[0] < arr[1] < ... < arr[peak]arr[peak] > arr[peak + 1] > ... > arr[n - 1]
Your task is to return the index of the peak element.
A correct solution should be better than linear scan when possible and should work for the mountain structure described above.
Input Format
- One integer array
arrrepresenting a mountain array. - The array has exactly one peak.
Output Format
- Return a single integer: the index of the peak element.
Constraints
3 <= arr.lengtharris guaranteed to be a mountain array- The peak is unique
- Values in the array are integers
Examples
Sample cases returned by the problem API.
Example 1
Input
arr = [0, 2, 4, 3, 1]
Output
2
Explanation
The values increase up to 4 at index 2, then decrease afterward, so the peak index is 2.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.