First Peak
A peak of the list nums is an item strictly bigger than each neighbour it has (the first item only has a right neighbour and the last item only has a left neighbour). A list with one item has its single item as a peak.
Return the index of the first (leftmost) peak, or -1 if there is none.
Example 1
nums [1,3,2,4,1]
returns 1
3 is bigger than 1 and 2, so index 1.
Example 2
nums [2,2,2]
returns -1
No item is strictly bigger than its neighbours.
Constraints
1 <= len(nums) <= 40-100 <= nums[i] <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Arrays problems
- Largest DrawdownEasy
- Left Steps to MatchEasy
- Missing RangesEasy
- Monotonic ArrayEasy
- Nearest Aligned PointEasy
- Outside InEasy
- Pascal RowEasy
- Plurality WinnerEasy