Valid Mountain Array

Easy
10
68.3% Acceptance

In this lab, you will be implementing a function to check if a given array of integers represents a valid mountain array or not. You will be using ESM import/export everywhere. Make sure to follow all the rules mentioned above while building the lab.

A valid mountain array is an array that follows these rules:

  • arr.length >= 3
  • There exists some i with 0 < i < arr.length - 1 such that:
    • arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
    • arr[i] > arr[i + 1] > ... > arr[arr.length - 1]

Examples:

  1. For arr = [2, 1], the output should be false as the length of the array is less than 3.
  2. For arr = [3, 5, 5], the output should be false because the values don't strictly decrease after the peak value.
  3. For arr = [0, 3, 2, 1], the output should be true as it satisfies all the conditions of a valid mountain array.

Challenges

  1. Write a function validMountainArray that receives an array of integers as input and returns true if it is a valid mountain array, otherwise false.
  2. Export the validMountainArray function from your code file.