#K16196. Zig-Zag Pattern Check
Zig-Zag Pattern Check
Zig-Zag Pattern Check
Given a sequence of integers representing toy types picked by a customer, determine whether the sequence forms a zig-zag pattern.
A sequence is defined as zig-zag if for every element (except the first and last), one of the following conditions holds:
- The element is a local maximum, i.e. it is strictly greater than both its neighbors.
- The element is a local minimum, i.e. it is strictly less than both its neighbors.
Note: Sequences with fewer than two elements are automatically considered zig-zag.
You are given multiple test cases. For each test case, output "YES" if the sequence is zig-zag, otherwise output "NO".
inputFormat
The input begins with an integer T (the number of test cases).
For each test case, the first line contains an integer N (the length of the sequence), followed by a line with N space-separated integers denoting the sequence.
outputFormat
For each test case, print a single line: "YES" if the sequence forms a zig-zag pattern, or "NO" otherwise.
## sample4
3
1 3 2
4
4 1 3 2
5
1 2 3 4 5
1
100
YES
YES
NO
YES
</p>