All problems
0860EasyArrayEnumeration

Ridge Points Along the Profile

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2951Find the Peaks

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A survey profile is given as mountain, where mountain[i] is the height at station i.

A station is a ridge point when it is strictly higher than the station on each side of it. The first and last stations are never ridge points, since each has only one neighbour.

Return the ridge point stations in increasing order.

Examples

Example 1

Input
mountain = [2, 5, 3, 6, 4]
Output
[1, 3]

Station 1 stands at 5 above the 2 and the 3 beside it, and station 3 stands at 6 above the 3 and the 4 beside it.

Example 2

Input
mountain = [1, 3, 3, 1]
Output
[]

Stations 1 and 2 are both at height 3, so neither stands strictly above both of its neighbours.

Example 3

Input
mountain = [1, 2, 3]
Output
[]

The only station with a neighbour on each side is station 1, and it stands below station 2.

Constraints

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

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def ridge_points(mountain: list[int]) -> list[int]:
Java
public List<Integer> ridgePoints(int[] mountain)
September 7
Apply