#K14046. Valid Peak Pattern
Valid Peak Pattern
Valid Peak Pattern
You are given an integer sequence. Determine whether the sequence forms a valid peak pattern. A valid peak pattern is defined as one that strictly increases to a single peak and then strictly decreases afterward. In other words, there exists an index (k) (with (1 < k < n)) such that:
[ a_1 < a_2 < \cdots < a_k \quad \text{and} \quad a_k > a_{k+1} > \cdots > a_n, ]
with (n) being the length of the sequence. Note that no two consecutive elements are allowed to be equal.
inputFormat
The first line of input contains a single integer (n) (where (3 \le n \le 10^5)), representing the number of elements in the sequence. The second line contains (n) space-separated integers.
outputFormat
Output a single line: print “YES” if the sequence forms a valid peak pattern; otherwise, print “NO”.## sample
7
1 2 4 5 3 2 1
YES
</p>