We’re preparing your current view and syncing the latest data.
Given an array of integers arr, return true if and only if it is a valid mountain array.
Recall that arr is a mountain array if and only if:
In other words, the array must strictly increase to a peak and then strictly decrease.
An integer array arr.
Return true if arr is a valid mountain array, otherwise false.
3 <= arr.length <= 10^4 0 <= arr[i] <= 10^4
Example 1
Input
[2,1]
Output
false
Explanation
The array length is less than 3, so it cannot form a mountain.
Example 2
Input
[3,5,5]
Output
false
Explanation
The peak is not strictly greater than the previous element.
Example 3
Input
[0,3,2,1]
Output
true
Explanation
The array has a strictly increasing sequence followed by a strictly decreasing sequence.