Problem Description
Given an array of mountain heights and a threshold value, identify all mountain indices (except the first mountain) where the mountain immediately preceding them has a height strictly greater than the threshold.
Key Insights
- Only consider mountains starting from index 1 as mountain 0 has no preceding mountain.
- For each mountain at index i, simply check if height[i-1] > threshold.
- The order of indices in the output array does not matter.
- The input size is small, so a simple linear traversal is efficient.
Space and Time Complexity
Time Complexity: O(n) where n is the number of mountains
Space Complexity: O(n) in the worst-case scenario for storing the resulting indices
Solution
Use a single loop starting from index 1 (since mountain 0 is not stable). For each mountain, check if the preceding mountain's height is greater than the threshold. If the condition is met, add the current mountain's index to the result list. This approach leverages constant-time comparisons and a simple list/dynamic array insertion.