#3285
Easy Algorithms Find indices of stable mountains
Array
86.8% acceptance
Feb 25, 2026
104
39
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.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn stable_mountains(height: Vec<i32>, threshold: i32) -> Vec<i32> {
(1..height.len())
.filter(|&i| height[i - 1] > threshold)
.map(|i| i as i32)
.collect()
}
}