easy +10 pts

Index of peak element

Find the index of any peak element in an integer array.

A peak element is an element that is strictly greater than its neighbors. For the first and last elements, only consider the single existing neighbor. Given a list of integers `arr`, implement `find_peak_index(arr)` that returns the index of **any** peak element. The input list will have at least one element. If multiple peaks exist, returning any valid peak index is acceptable.

Constraints

1 <= len(arr) <= 10^5, values are integers within Python's int range.

Example

>>> find_peak_index([1, 2, 3, 1])
2
>>> find_peak_index([1, 2, 1, 3, 5, 6, 4])
1
>>> find_peak_index([3, 2, 1])
0
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

A linear scan comparing each element to its neighbors is sufficient for this problem.
For edges, consider only the neighbor that exists.
If arr has length 1, the single element is a peak (index 0).
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.