3285. Find Indices of Stable Mountains LeetCode Solution

In this guide, you will get 3285. Find Indices of Stable Mountains LeetCode Solution with the best time and space complexity. The solution to Find Indices of Stable Mountains problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.

Table of Contents

  1. Problem Statement
  2. Complexity Analysis
  3. Find Indices of Stable Mountains solution in C++
  4. Find Indices of Stable Mountains solution in Java
  5. Find Indices of Stable Mountains solution in Python
  6. Additional Resources
3285. Find Indices of Stable Mountains LeetCode Solution image

Problem Statement of 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.

Example 1:

Input: height = [1,2,3,4,5], threshold = 2
Output: [3,4]
Explanation:

Mountain 3 is stable because height[2] == 3 is greater than threshold == 2.
Mountain 4 is stable because height[3] == 4 is greater than threshold == 2.

Example 2:

Input: height = [10,1,10,1,10], threshold = 3
Output: [1,3]

Example 3:

Input: height = [10,1,10,1,10], threshold = 10
Output: []

Constraints:

2 <= n == height.length <= 100
1 <= height[i] <= 100
1 <= threshold <= 100

Complexity Analysis

  • Time Complexity: O(n)
  • Space Complexity: O(n)

3285. Find Indices of Stable Mountains LeetCode Solution in C++

class Solution {
 public:
  vector<int> stableMountains(vector<int>& height, int threshold) {
    vector<int> ans;

    for (int i = 1; i < height.size(); ++i)
      if (height[i - 1] > threshold)
        ans.push_back(i);

    return ans;
  }
};
/* code provided by PROGIEZ */

3285. Find Indices of Stable Mountains LeetCode Solution in Java

class Solution {
  public List<Integer> stableMountains(int[] height, int threshold) {
    List<Integer> ans = new ArrayList<>();

    for (int i = 1; i < height.length; ++i)
      if (height[i - 1] > threshold)
        ans.add(i);

    return ans;
  }
}
// code provided by PROGIEZ

3285. Find Indices of Stable Mountains LeetCode Solution in Python

class Solution:
  def stableMountains(self, height: list[int], threshold: int) -> list[int]:
    return [i for i in range(1, len(height))
            if height[i - 1] > threshold]
# code by PROGIEZ

Additional Resources

Happy Coding! Keep following PROGIEZ for more updates and solutions.