## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## [Solution] Minimum or Maximum CodeChef Solution | CodeChef Problem Solution 2022

From a hidden array $A$ of length $N$, Stack constructs an array $B$ of length $N$ such that:

• For all $i$ $\left(1\le i\le N\right)$${B}_{i}=max\left({A}_{1},{A}_{2},\dots ,{A}_{i}\right)$ or ${B}_{i}=min\left({A}_{1},{A}_{2},\dots ,{A}_{i}\right)$.

For the given array $B$ of length $N$, Stack wants you to check whether a possible array $A$ exists or not.

### Input Format

• The first line of input contains a single integer $T$, denoting the number of test cases. The description of $T$ test cases follow.

• The first line of each test case contains an integer $N$ - the length of the array $B$.
• The second line of each test case contains $N$ space-separated integers ${B}_{1},{B}_{2},\dots ,{B}_{N}$ representing the array $B$.

### Output Format

For each test case, output in a single line YES if $A$ exists, otherwise print NO.

You may print each character of the string in uppercase or lowercase (for example, the strings YESyEsyes, and yeS will all be treated as identical).