## GUPTA MECHANICAL

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

## Pseudo Sorted Array Solution | CodeChef Problem Solution 2022 | April Long Two

An array $A$ of length $N$ is said to be pseudo-sorted if it can be made non-decreasing after performing the following operation at most once.

• Choose an $i$ such that $1\le i\le N-1$ and swap ${A}_{i}$ and ${A}_{i+1}$

Given an array $A$, determine if it is pseudo-sorted or not.

### 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$.
• The second line of each test case contains $N$ space-separated integers ${A}_{1},{A}_{2},\dots ,{A}_{N}$ denoting the array $A$.

### Output Format

For each testcase, output YES if the array $A$ is pseudo-sorted, NO otherwise.

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

### Constraints

• $1\le T\le 1000$
• $2\le N\le {10}^{5}$
• $1\le {A}_{i}\le {10}^{9}$
• Sum of $N$ over all test cases do not exceed $2\cdot {10}^{5}$

### Sample Input 1

3
5
3 5 7 8 9
4
1 3 2 3
3
3 2 1


### Sample Output 1

YES
YES
NO


### Explanation

Test case 1: The array is already sorted in non-decreasing order.

Test case 2: We can choose $i=2$ and swap ${A}_{2}$ and ${A}_{3}$. The resulting array will be $\left[1,2,3,3\right]$, which is sorted in non-decreasing order.

Test case 3: It can be proven that the array cannot be sorted in non-decreasing order in at most one operation.