#K41172. Lexicographically Smallest Array
Lexicographically Smallest Array
Lexicographically Smallest Array
Given an array of integers, you are allowed to reverse any subarray of length (\ge 2) any number of times. Reversing a subarray of length 2 is equivalent to swapping two adjacent elements. It can be proven that using these operations, the lexicographically smallest array achievable is the array sorted in ascending order.
For each test case, you will be given the number of elements followed by the array itself. Your task is to output the lexicographically smallest array (i.e. the sorted array) as space-separated integers.
inputFormat
The input begins with an integer (T) on the first line, denoting the number of test cases. For each test case, 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 containing the lexicographically smallest array (i.e. the sorted array) as space-separated integers.## sample
3
5
3 1 2 4 5
4
9 8 7 6
3
1 2 3
1 2 3 4 5
6 7 8 9
1 2 3
</p>