Find Indices of Stable Mountains - Problem
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: Mountain 0 is not stable.
Return an array containing the indices of all stable mountains in any order.
Input & Output
Example 1 — Basic Case
$
Input:
height = [1,2,3,4,5], threshold = 2
›
Output:
[3,4]
💡 Note:
Mountain 3 is stable because height[2] = 3 > 2. Mountain 4 is stable because height[3] = 4 > 2. Mountains 0,1,2 are not stable.
Example 2 — No Stable Mountains
$
Input:
height = [2,1,1], threshold = 5
›
Output:
[]
💡 Note:
No mountain is stable because height[0] = 2 ≤ 5 and height[1] = 1 ≤ 5.
Example 3 — All Mountains Stable
$
Input:
height = [10,1,10,1,10], threshold = 3
›
Output:
[1,3]
💡 Note:
Mountains 1 and 3 are stable because height[0] = 10 > 3 and height[2] = 10 > 3. Mountains 2 and 4 are not stable because height[1] = 1 ≤ 3 and height[3] = 1 ≤ 3.
Constraints
- 1 ≤ height.length ≤ 100
- 1 ≤ height[i] ≤ 100
- 1 ≤ threshold ≤ 100
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code