#K45147. Mountain Array Verification
Mountain Array Verification
Mountain Array Verification
You are given an array of integers. An array is considered a mountain array if and only if:
- The array has at least 3 elements.
- There exists an index \( i \) with \( 1 \leq i \leq n-2 \) such that:
- The sequence \( a_0, a_1, \dots, a_i \) is strictly increasing.
- The sequence \( a_i, a_{i+1}, \dots, a_{n-1} \) is strictly decreasing.
Your task is to read an array from the standard input and determine whether the array is a mountain array. Print YES
if it is, or NO
otherwise.
Note: The input is provided from stdin
and the result should be printed to stdout
.
inputFormat
The input consists of two lines:
- The first line contains a single integer \( n \) ( \( n \geq 1 \)), representing the number of elements in the array.
- The second line contains \( n \) space-separated integers \( a_0, a_1, \dots, a_{n-1} \) representing the elements of the array.
outputFormat
Print a single line to stdout
:
YES
if the array is a mountain array.NO
otherwise.
2
2 1
NO