[LeetCode] Find Indices of Stable Mountains

3285. Find Indices of Stable Mountains

There are n mountains in a row, and each mountain has a height. You are given an integer array height where height[i] represents the height of mountain i, and an integer threshold.

A mountain is called stable if the mountain just before it (if it exists) has a height strictly greater than threshold. Note that mountain 0 is not stable.

Return an array containing the indices of all stable mountains in any order.

1
2
3
4
5
6
7
8
9
10
11
package main

func stableMountains(height []int, threshold int) []int {
res := []int{}
for i := 1; i < len(height); i++ {
if height[i-1] > threshold {
res = append(res, i)
}
}
return res
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2024/09/15/PS/LeetCode/find-indices-of-stable-mountains/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.