Find the Peaks

You are given a 0-indexed array mountain. Your task is to find all the peaks in the mountain array.

Return an array that consists of indices of peaks in the given array in any order.

Notes:

  • A peak is defined as an element that is strictly greater than its neighboring elements.
  • The first and last elements of the array are not a peak.
Example 1
Inputmountain = [2,4,4]
Output[]
The first and last elements cannot be peaks, and mountain[1] is not strictly greater than mountain[2], so there are no peaks.
Example 2
Inputmountain = [1,4,3,8,5]
Output[1,3]
The first and last elements cannot be peaks, while mountain[1] and mountain[3] are strictly greater than their neighboring elements.

Constraints

  • 3 <= mountain.length <= 100
  • 1 <= mountain[i] <= 100

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate