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
with0 < 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:
- For
arr = [2, 1]
, the output should befalse
as the length of the array is less than 3. - For
arr = [3, 5, 5]
, the output should befalse
because the values don't strictly decrease after the peak value. - For
arr = [0, 3, 2, 1]
, the output should betrue
as it satisfies all the conditions of a valid mountain array.
Challenges
- Write a function
validMountainArray
that receives an array of integers as input and returnstrue
if it is a valid mountain array, otherwisefalse
. - Export the
validMountainArray
function from your code file.