#C7856. Valid Mountain Array
Valid Mountain Array
Valid Mountain Array
You are given an array of integers. Your task is to determine whether the given array is a valid mountain array. An array is considered a mountain array if and only if:
- The array contains at least 3 elements.
- There exists an index \( i \) (with \( 0 < i < n-1 \)) such that:
- \( arr[0] < arr[1] < ... < arr[i-1] < arr[i] \) (strictly increasing up to the peak), and
- \( arr[i] > arr[i+1] > ... > arr[n-1] \) (strictly decreasing after the peak).
If the above conditions are met, output "YES", otherwise output "NO".
Input and Output via Standard Streams: The input is read from standard input (stdin) and output is written to standard output (stdout).
inputFormat
The first line contains an integer \( n \), the number of elements in the array. The second line contains \( n \) space-separated integers representing the array elements.
Example:
4 0 3 2 1
outputFormat
Output a single string "YES" if the array forms a valid mountain array, otherwise output "NO".
Example:
YES## sample
2
2 1
NO