LeetCode 3285: Find Indices of Stable Mountains Solution

Master LeetCode problem 3285 (Find Indices of Stable Mountains), a easy challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.

3285. Find Indices of Stable Mountains

Easy

Problem Explanation

Explanation

To solve this problem, we iterate through the array of mountain heights, starting from index 1. For each mountain, we check if its height is greater than the threshold and if the previous mountain's height is also greater than the threshold. If both conditions are met, we consider the mountain stable and add its index to the result array.

Algorithm:

  1. Initialize an empty list to store the indices of stable mountains.
  2. Iterate through the array starting from index 1.
  3. Check if the current mountain's height is greater than the threshold and the previous mountain's height is also greater than the threshold.
  4. If both conditions are met, add the index of the current mountain to the result list.
  5. Return the list of indices of stable mountains.

Time Complexity

The time complexity of this algorithm is O(n), where n is the number of mountains.

Space Complexity

The space complexity is O(1) since we only use a constant amount of extra space.

Solution Code

import java.util.ArrayList;
import java.util.List;

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

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

        return result;
    }
}

Try It Yourself

Loading code editor...

Related LeetCode Problems

Frequently Asked Questions

How to solve LeetCode 3285 (Find Indices of Stable Mountains)?

This page provides optimized solutions for LeetCode problem 3285 (Find Indices of Stable Mountains) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.

What is the time complexity of LeetCode 3285 (Find Indices of Stable Mountains)?

The time complexity for LeetCode 3285 (Find Indices of Stable Mountains) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.

Can I run code for LeetCode 3285 on DevExCode?

Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 3285 in Java, C++, or Python.

Back to LeetCode Solutions