Find Indices of Stable Mountains

EasyArray

Solution

export function stableMountains(height: number[], threshold: number): number[] {
  const n = height.length;
  const answer: number[] = [];
  for (let i = 1; i < n; i++) {
    if (height[i - 1] > threshold) {
      answer.push(i);
    }
  }
  return answer;
}

Complexity

  • Time: O(N)
  • Space: O(1)