Ctrl K

Ridge Summits

Easy
Hikers walked along a mountain ridge and recorded the heights of the points on their route, in order, in the array heights. A **summit** is a point strictly higher than both of its neighbours. The first and last points of the route never count as summits, since each has only one neighbour. Return the indices of all summits (0-based) in any order.
Example 1
heights=[3, 7, 5, 6, 6, 2, 9] → [1]

Point 1 (height 7) is higher than both neighbours. Points 3 and 4 have equal height 6, so neither is strictly higher, and point 6 is an end point, which never counts.

Example 2
heights=[9, 4, 1] → []

The only inner point is lower than its left neighbour.

Example 3
heights=[1, 5, 1, 5, 1] → [1, 3]
Constraints
  • 3 ≤ len(heights) ≤ 100
  • 1 ≤ heights[i] ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsConsistent Reading Triples EasyRepeated Block Run EasyXOR of Every Subset EasyThree Addends and a Later Total EasyEven Numbers From Digit Cards Easy
loading Python…
Input
heights=[3, 7, 5, 6, 6, 2, 9]
Expected
[1]

Run checks the first 3 tests in your browser. Submit checks all 116 tests on the server, hidden ones included.