Determine whether an array rises strictly to a single peak and then falls strictly, forming a mountain shape.
Given an integer array arr, determine whether it forms a valid mountain array.
An array is a valid mountain array if:
peak with 0 < peak < n - 1,arr[0] to arr[peak], andarr[peak] to arr[n - 1].Return true if the array is a valid mountain array, otherwise return false.
A valid mountain must have exactly one peak and no plateaus.
arr.true if arr is a valid mountain array; otherwise return false.Example 1
Input
arr = [0,3,2,1]
Output
true
Explanation
The array strictly increases from 0 to 3, then strictly decreases from 3 to 1, with a single peak at index 1.
Example 2
Input
arr = [3,5,5]
Output
false
Explanation
The values do not strictly increase and then strictly decrease because 5 is repeated, creating a plateau.
Example 3
Input
arr = [2,1]
Output
false
Explanation
The array is too short to form a mountain.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.