[Solution] Concat Sort CodeChef Solution 2022
Problem
JJ has an array . He can perform the following operation on :
- Divide into two subsequences and such that each belongs to either or .
- Set
Here denotes the concatenation operation. For e.g. .
Is it possible to make sorted in non-decreasing order after applying the above operation at most once?
Note: An array is a subsequence of an array if can be obtained by deletion of several (possibly, zero or all) elements from .
Input Format
- The first line contains a single integer — the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer — the size of the array .
- The second line of each test case contains space-separated integers denoting the array .
Output Format
For each test case, output YES
if it is possible to make the array 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, yes
, yEs
, Yes
will be considered identical).
Explanation:
Test case : We can select and . Therefore will become which is sorted.
Test case : It can be proven that it is not possible to sort by using the given operation at most once.
Test case : We can select and . Therefore will become which is sorted.
No comments:
Post a Comment