JuniorArray

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
        #
      # #
    # # #
  # # # #
# # # # #
1 2 3 4 5
Inputheight = [1,2,3,4,5], threshold = 2
Output[3,4]
Mountain 3 is stable because height[2] == 3 is greater than threshold == 2, and mountain 4 is stable because height[3] == 4 is greater than threshold == 2.
Example 2
 #     #     #
 #     #     #
 #     #     #
 #     #     #
 #     #     #
 #     #     #
 #     #     #
 #     #     #
 #     #     #
 #  #  #  #  #
10  1 10  1 10
Inputheight = [10,1,10,1,10], threshold = 3
Output[1,3]
Mountains 1 and 3 are stable because the mountains immediately before them have heights 10, which is greater than 3.

Constraints

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

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate