#K80307. Zigzag Sequence Checker
Zigzag Sequence Checker
Zigzag Sequence Checker
You are given a sequence of integers. Your task is to determine whether the given sequence is a Zigzag Sequence.
A sequence \(a_0, a_1, \ldots, a_{n-1}\) is called a Zigzag Sequence if for every index \(i\) (where \(1 \le i \le n-2\)) the following condition holds:
\[ (a_{i-1} a_{i+1}) \quad \text{or} \quad (a_{i-1} > a_i < a_{i+1}) \]
For sequences with fewer than two elements, or exactly two elements which are equal, the sequence is not considered a Zigzag Sequence.
Input Format: The first line contains a single integer \(n\) representing the number of elements in the sequence. If \(n > 0\), the second line contains \(n\) space-separated integers representing the sequence.
Output Format: Print True
if the sequence is a Zigzag Sequence; otherwise print False
.
inputFormat
The input is given from stdin and consists of:
- A single integer \(n\) (\(n \ge 0\)), the number of elements in the sequence.
- If \(n > 0\), a line with \(n\) space separated integers.
outputFormat
Output a single line to stdout containing either True
or False
depending on whether the sequence is a Zigzag Sequence.
0
False
</p>