#C4240. Reconstructing Array X
Reconstructing Array X
Reconstructing Array X
You are given an array \(Y\) of \(N\) integers. Your task is to determine whether the array forms a valid monotonic sequence. That is, check if \(Y\) is either non-decreasing (i.e. \(Y_1 \le Y_2 \le \ldots \le Y_N\)) or non-increasing (i.e. \(Y_1 \ge Y_2 \ge \ldots \ge Y_N\)). If one of these conditions holds, you can reconstruct an array \(X\) based on \(Y\) and the answer is YES
; otherwise, the answer is NO
.
Note: An array with a single element is considered monotonic.
inputFormat
The first line contains an integer \(T\), the number of test cases. Then for each test case, the first line contains an integer \(N\) representing the number of elements in the array \(Y\). The next line contains \(N\) space-separated integers representing the elements of \(Y\).
outputFormat
For each test case, output a single line containing either YES
if the array \(Y\) is monotonic, or NO
otherwise.
5
1
42
4
4 4 2 2
3
3 1 2
5
1 1 1 1 1
5
1 3 2 4 5
YES
YES
NO
YES
NO
</p>