Show problems as
Classic problem #3285EasyArray

Find Indices of Stable Mountains

Real-world version: Peaks Behind a Tall Neighbour
Tracked in this browser only
Read Find Indices of Stable Mountains on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

Peak heights along a ridge are given as height, and a cut-off is given as threshold.

A peak is sheltered when the peak directly before it on the ridge stands strictly higher than the cut-off. The first peak has nothing before it, so it is never sheltered.

Return the positions of the sheltered peaks, in increasing order.

Examples

Example 1

Input
height = [9, 3, 14, 6, 11], threshold = 7
Output
[1, 3]

Position 1 sits behind the peak of 9, which clears 7. Position 2 sits behind the peak of 3, which does not. Position 3 sits behind 14 and position 4 behind 6, so only the first of those counts.

Example 2

Input
height = [3, 3, 3, 3], threshold = 3
Output
[]

Every peak matches the cut-off without clearing it, so nothing is sheltered.

Example 3

Input
height = [5, 6, 7, 8, 9], threshold = 4
Output
[1, 2, 3, 4]

Every peak clears the cut-off, so every position from 1 onwards is sheltered.

Constraints

  • 2 <= height.length <= 100
  • 1 <= height[i] <= 100
  • 1 <= threshold <= 100

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def stable_mountains(height: list[int], threshold: int) -> list[int]:
Java
public List<Integer> stableMountains(int[] height, int threshold)