#K52042. Peak Sequence Detection
Peak Sequence Detection
Peak Sequence Detection
A sequence of integers \(a_1, a_2, \dots, a_n\) is called a peak sequence if there exists an index \(k\) such that \(1 < k < n\) and the following conditions hold:
\(a_1 < a_2 < \dots a_{k+1} > \dots > a_n\).
In other words, the sequence must strictly increase to a single maximum element and then strictly decrease. Note that no two adjacent elements may be equal.
inputFormat
The input is read from stdin and contains multiple test cases. The first line contains an integer \(T\), representing the number of test cases. Each test case consists of two lines:
- The first line contains an integer \(n\) representing the length of the sequence.
- The second line contains \(n\) space-separated integers representing the sequence.
outputFormat
For each test case, output a single line to stdout containing "YES" if the sequence is a peak sequence, or "NO" otherwise.
## sample5
5
1 3 5 4 2
4
2 3 3 2
6
1 2 3 4 5 6
3
1 3 2
4
1 2 1 1
YES
NO
NO
YES
NO
</p>