#K76657. Mountain Array
Mountain Array
Mountain Array
You are given an array of integers. Your task is to determine whether the array is a 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 the sequence strictly increases up to i and then strictly decreases after i.
In other words, if the array is denoted as $A_0, A_1, \ldots, A_{n-1}$, there must exist an index i satisfying:
$$A_0 < A_1 < \cdots A_{i+1} > \cdots > A_{n-1}.$$
If the given array satisfies these conditions, print YES
. Otherwise, print NO
.
inputFormat
The input is read from stdin and consists of two lines. The first line contains an integer n
(n \ge 1
), representing the number of elements in the array. The second line contains n
space-separated integers representing the elements of the array.
outputFormat
Output a single line to stdout with YES
if the array is a mountain array; otherwise, output NO
.
3
1 2 1
YES