#K5726. Special Sequence Verification
Special Sequence Verification
Special Sequence Verification
You are given a sequence of integers. A sequence is defined to be special if the absolute difference between any two consecutive elements is either 1 or 2. In other words, for a sequence \(a_1, a_2, \dots, a_n\), the sequence is special if for every \(i = 2, 3, \dots, n\) it holds that
[ |a_i - a_{i-1}| \in {1, 2} ]
Your task is to determine whether the given sequence is special.
Note: A sequence with only one element is always considered special.
inputFormat
The first line of input contains a single integer \(T\) representing the number of test cases. Each test case consists of two lines. The first line contains an integer \(N\), the number of elements in the sequence. The second line contains \(N\) space-separated integers representing the sequence.
outputFormat
For each test case, output a single line containing either "YES" if the sequence is special, or "NO" otherwise.
## sample3
3
1 2 3
4
1 3 5 7
5
5 6 4 3 7
YES
YES
NO
</p>