#C5196. Minimize Adjacent Differences
Minimize Adjacent Differences
Minimize Adjacent Differences
You are given T test cases. For each test case, you will receive an integer N and a sequence of N integers. Your task is to rearrange the sequence so as to minimize the absolute difference between any two adjacent numbers.
The optimal way to minimize the adjacent differences is to sort the sequence in non-decreasing order. In other words, you need to find an arrangement which minimizes the following quantity:
For each test case, output the rearranged array where the numbers are space-separated. Each test case’s output should appear on a new line.
inputFormat
The input is given via stdin in the following format:
T N a_1 a_2 ... a_N ... (repeated for each test case)
Where:
- T is the number of test cases.
- For each test case, the first line contains an integer N, followed by a line with N space-separated integers.
Note: Use LaTeX formatting for any formulas, e.g. $$T$$, $$N$$.
outputFormat
For each test case, print a single line containing the rearranged array (i.e. the array sorted in non-decreasing order) with each element separated by a space. The output should be written to stdout.
## sample1
5
3 1 2 4 5
1 2 3 4 5
</p>