#K1841. Mountain Sequence Checker
Mountain Sequence Checker
Mountain Sequence Checker
You are given several sequences of integers. Your task is to determine whether each sequence forms a mountain sequence.
A sequence is considered a mountain sequence if and only if it satisfies the following conditions:
- The sequence contains at least 3 elements.
- There exists an index \( i \) (with \(1 \leq i \leq n-2\)) such that the subsequence \(a_0, a_1, \dots, a_i\) is strictly increasing and the subsequence \(a_i, a_{i+1}, \dots, a_{n-1}\) is strictly decreasing.
- The peak element \(a_i\) is greater than both of its immediate neighbors (i.e. \(a_{i-1} a_{i+1}\)).
Input/Output Method: Read input from standard input (stdin) and write the result to standard output (stdout).
inputFormat
The first line of input contains an integer \(T\), representing the number of sequences.
For each sequence, the first number is an integer \(n\) representing the number of elements in the sequence, followed by \(n\) integers.
Example:
3 7 1 2 3 4 3 2 1 5 1 2 3 2 1 5 1 2 3 4 5
outputFormat
For each sequence, output a single line containing either YES
if the sequence is a mountain sequence, or NO
otherwise.
Example output:
YES YES NO## sample
3
7
1 2 3 4 3 2 1
5
1 2 3 2 1
5
1 2 3 4 5
YES
YES
NO
</p>