#K69482. Rearrange Student Heights
Rearrange Student Heights
Rearrange Student Heights
You are given a list of student heights. Your task is to rearrange the list such that the absolute difference between the heights of any two adjacent students is minimized. This goal can be achieved by sorting the list in ascending order.
In mathematical terms, given a sequence \(H = [h_1, h_2, \dots, h_n]\), you need to produce a sequence \(H' = [h'_1, h'_2, \dots, h'_n]\) such that \(h'_1 \leq h'_2 \leq \dots \leq h'_n\). This order minimizes the differences \(|h'_{i+1} - h'_i|\) for all \(1 \leq i < n\).
For example, if the input heights are [10, 5, 15, 20], the correct output is [5, 10, 15, 20].
inputFormat
The first line of input contains an integer \(n\) representing the number of students. The second line contains \(n\) space-separated integers, each representing a student's height.
outputFormat
Output a single line containing the sorted list of heights in ascending order, with each number separated by a single space.
## sample4
10 5 15 20
5 10 15 20