Loading...
You are given an integer array nums.
An index i is a peak if nums[i] is strictly greater than both of its adjacent elements, i.e. nums[i] > nums[i-1] and nums[i] > nums[i+1]. The first and last indices are never peaks, since they do not have two adjacent elements.
Return the indices of all peaks, in ascending order. If there are no peaks, return an empty array.
Input: nums = [5, 10, 7, 8, 6, 9, 3]
Output: [1, 3, 5]
Explanation: nums[1] = 10 is greater than 5 and 7; nums[3] = 8 is greater
than 7 and 6; nums[5] = 9 is greater than 6 and 3.
Input: nums = [1, 2, 3, 3, 2]
Output: []
Explanation: nums[2] = 3 is not strictly greater than nums[3] = 3, and no
other interior index exceeds both neighbors, so there are no peaks.
nums.length ≤105nums[i] ≤109Click "Run" to test with sample cases or "Submit" to run all tests.