#C4308. Taco Card Sorting Challenge
Taco Card Sorting Challenge
Taco Card Sorting Challenge
In the Taco Card Sorting Challenge, you are given several test cases, each representing a set of cards arranged in a circular order. Your task is to determine whether it is possible to sort the cards in non-decreasing order by performing a series of swaps under the following rules:
- If the cards are already in non-decreasing order, the answer is (YES).
- Otherwise, if all the card values in the test case are distinct, then it is always possible to sort them using swaps, so the answer is (YES).
- If there are any duplicate cards and the sequence is not already sorted, then the answer is (NO).
The input is provided via standard input and the output is expected on standard output. Use efficient operations to check sorting and uniqueness when necessary.
inputFormat
The first line of the input contains an integer (T) representing the number of test cases. Each test case consists of two lines. The first line of each test case contains an integer (n), the number of cards. The second line contains (n) space-separated integers representing the card values.
outputFormat
For each test case, output a single line containing (YES) if it is possible to sort the cards according to the rules described, or (NO) otherwise.## sample
1
1
1
YES
</p>