Find Indices of Stable Mountains
Real-world version: Peaks Behind a Tall NeighbourThe 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.
def stable_mountains(height: list[int], threshold: int) -> list[int]:public List<Integer> stableMountains(int[] height, int threshold)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's