Back to course home
0% completed
Solution: Valid Mountain Array
Problem Statement
Given an integer array arr
, return true
if arr
is a valid mountain
array. Otherwise, return false
.
The array is called a valid mountain array
if:
arr.length > 2
- 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
Example 1:
- Input: arr =
[4, 5, 6, 7, 8, 7, 6, 5]
- Expected Output:
true
- Justification: The elements increase from
4
to8
and then decrease from8
back to `5
.....
.....
.....
Like the course? Get enrolled and start learning!