easy +10 pts

Find Peak Index

Find any index where a number is greater than or equal to its neighbors in a list.

Write a function `find_peak_index(nums)` that takes a list of integers `nums` (length at least 1) and returns the index of **any** peak element. A peak element is an element that is **greater than or equal to** its left and right neighbors. For boundary elements, only consider the existing neighbor(s). The list may contain duplicates, and there is always at least one peak. Your function should return the **first** such index (lowest index) that satisfies the peak condition.

Constraints

1 <= len(nums) <= 10^5\n-10^9 <= nums[i] <= 10^9\nTime complexity: O(n) is acceptable; O(log n) is optional but not required.

Example

>>> find_peak_index([1,2,3,1])\n2\n>>> find_peak_index([1,2,1,3,5,6,4])\n1\n>>> find_peak_index([1,1,1])\n0\n>>> find_peak_index([5])\n0
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

A peak exists always, but you just need the first one.
Check each index from left to right and verify the condition with its neighbors.
For index 0, only compare with the right neighbor; for the last index, only with the left neighbor.
Duplicates: if two equal elements are adjacent, the left one still satisfies the condition if it's >= its neighbors.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.