All problems
0913EasyArray

Peaks Behind a Tall Neighbour

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3285Find Indices of Stable Mountains

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.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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