#K65332. Almost Sorted Array

    ID: 32174 Type: Default 1000ms 256MiB

Almost Sorted Array

Almost Sorted Array

You are given an array of integers. Your task is to determine if it is possible to transform the array into a non‐decreasing sorted array by modifying at most one element.

An array A is considered sorted in non-decreasing order if for all valid indices i, it satisfies $$A[i] \leq A[i+1]$$.

For each test case, print YES if the array can be made sorted by changing at most one element; otherwise print NO.

inputFormat

The input begins with an integer T, representing the number of test cases. Each test case consists of two lines. The first line contains an integer N, the number of elements in the array. The second line contains N space‐separated integers representing the array.

outputFormat

For each test case, output a single line with either YES or NO indicating whether the array can be transformed into a sorted array by modifying at most one element.

## sample
5
5
10 5 7 8 9
4
1 5 3 4
3
7 8 9
3
3 2 1
5
2 3 3 2 1
YES

YES YES NO NO

</p>