#K75507. Monotonic Array Check

    ID: 34434 Type: Default 1000ms 256MiB

Monotonic Array Check

Monotonic Array Check

Given an array of integers, determine whether the array is monotonic. An array is monotonic if it is either non-decreasing or non-increasing.

More formally, an array \(a_1, a_2, \ldots, a_n\) is monotonic if it satisfies one of the following:

  • \(a_1 \le a_2 \le \cdots \le a_n\)
  • \(a_1 \ge a_2 \ge \cdots \ge a_n\)

Your task is to process multiple test cases. For each test case, output "Yes" if the array is monotonic, and "No" otherwise.

inputFormat

The input is given via standard input (stdin) and has the following format:

T
N1
a11 a12 ... a1N1
N2
a21 a22 ... a2N2
... 
NT
aT1 aT2 ... aTN_T

Where:

  • T is the number of test cases.
  • For each test case, the first line contains an integer N, the size of the array, and the second line contains N space-separated integers.

outputFormat

For each test case, print a single line containing either "Yes" if the given array is monotonic (either non-decreasing or non-increasing), or "No" otherwise.

## sample
1
4
1 2 2 3
Yes

</p>