## GUPTA MECHANICAL

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

# [Solution] Concat Sort CodeChef Solution 2022

## Problem

JJ has an array $A$. He can perform the following operation on $A$:

• Divide $A$ into two subsequences $P$ and $Q$ such that each $A_i$ belongs to either $P$ or $Q$.
• Set $A := P\ \texttt{concat}\ Q$

Here $\texttt{concat}$ denotes the concatenation operation. For e.g. $[2, 1, 5] \texttt{ concat } [4, 3] = [2, 1, 5, 4, 3]$.

Is it possible to make $A$ sorted in non-decreasing order after applying the above operation at most once?

Note: An array $X$ is a subsequence of an array $Y$ if $X$ can be obtained by deletion of several (possibly, zero or all) elements from $Y$.

### Input Format

• The first line contains a single integer $T$ — the number of test cases. Then the test cases follow.
• The first line of each test case contains an integer $N$ — the size of the array $A$.
Solution Click Below:-  👉
👇👇👇👇👇

• The second line of each test case contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$ denoting the array $A$.

### Output Format

For each test case, output YES if it is possible to make the array $A$ sorted after applying the given operation at most once. Otherwise, output NO.

You may print each character of YES and NO in uppercase or lowercase (for example, yesyEsYes will be considered identical).

### Explanation:

Test case $1$: We can select $P = [1, 2, 3]$ and $Q = [4, 5, 6]$. Therefore $A$ will become $[1, 2, 3, 4, 5, 6]$ which is sorted.

Test case $2$: It can be proven that it is not possible to sort $A$ by using the given operation at most once.

Test case $3$: We can select $P = [5, 7, 9]$ and $Q = [10, 11]$. Therefore $A$ will become $[5, 7, 9, 10, 11]$ which is sorted.