#K8716. Peak Sequence Rearrangement
Peak Sequence Rearrangement
Peak Sequence Rearrangement
You are given an integer array of length (n). Your task is to determine whether the array can be rearranged to form a Peak Sequence. A peak sequence is one that first (strictly) increases and then (strictly) decreases. In this problem, we consider that a peak sequence can only be formed if (n \ge 3) and not all elements are identical. More formally, let the given array be (A) of size (n). You should output "YES" if (n \ge 3) and (\exists, i, j) (with (1 \le i, j \le n)) such that (A_i \neq A_j). Otherwise, output "NO".
Note: Even if the array is already sorted in strictly increasing or strictly decreasing order, it is considered valid as long as it meets the conditions above.
inputFormat
The input is read from standard input (stdin). The first line contains a single integer (T) representing the number of test cases. Each of the next (T) lines contains a test case in the following format:
(n) (a_1) (a_2) ... (a_n)
where (n) is the number of elements in the array, and (a_1, a_2, \ldots, a_n) are the integer values of the array.
outputFormat
For each test case, output a single line to standard output (stdout) containing "YES" if the given array can be rearranged to form a valid Peak Sequence, or "NO" otherwise.## sample
3
5 1 3 2 4 5
4 5 5 5 5
6 9 8 7 6 5 4
YES
NO
YES
</p>