#K51907. Peak Building
Peak Building
Peak Building
Given a sequence representing the heights of buildings, determine if there exists an index ( k ) (1-indexed) such that all buildings to the left (if any) are in non-decreasing order and all buildings to the right (if any) are in non-increasing order. In other words, find if one can choose a building as the peak satisfying ( a_1 \le a_2 \le \cdots \le a_k ) and ( a_k \ge a_{k+1} \ge \cdots \ge a_n ), where ( n ) is the total number of buildings. If such an index exists, output "YES"; otherwise, output "NO".
inputFormat
The input is read from standard input (stdin). The first line contains an integer ( T ), denoting the number of test cases. Each test case consists of two lines: the first line contains an integer ( n ) (the number of buildings), and the second line contains ( n ) space-separated integers representing the heights of the buildings.
outputFormat
For each test case, output a single line to standard output (stdout) containing "YES" if there exists a peak building as described; otherwise, output "NO".## sample
4
7
1 2 3 5 4 3 2
3
1 2 1
5
2 2 2 2 2
4
1 3 2 4
YES
YES
YES
NO
</p>