The Find Indices of Stable Mountains coding problem asks you to identify "stable" mountains based on a height threshold and their predecessor's height. You are given an array of heights and a threshold. A mountain at index is considered stable if the mountain immediately before it (at index ) has a height strictly greater than the threshold. You need to return all valid indices .
Google uses this "Easy" question to test basic array indexing and attention to problem descriptions. It is a test of "Relative State"—making a decision about an element based on its neighbor. It checks if you can handle 0-based indexing correctly and whether you can avoid common off-by-one errors when looking at .
This problem uses a Linear Scan.
height[i-1] > threshold, add to your result list.heights = [1, 2, 1, 3, 5], threshold = 2
height[i] to the threshold instead of height[i-1].IndexOutOfBounds error.Simple problems are about precision. Read the definition of "stable" carefully. If it depends on the previous element, your loop must start at 1. If it depended on the next element, your loop would end at .