#K81527. Rearrange List to Minimize Absolute Difference on Consecutive Elements

    ID: 35773 Type: Default 1000ms 256MiB

Rearrange List to Minimize Absolute Difference on Consecutive Elements

Rearrange List to Minimize Absolute Difference on Consecutive Elements

Given a list of n integers, rearrange the list such that the absolute difference between any two consecutive integers is minimized. Mathematically, for a sorted list \(a_1 \le a_2 \le \dots \le a_n\), the sequence minimizes \(|a_{i+1} - a_i|\) for all \(1 \le i < n\).

For example, rearranging the list [4, 2, 1, 3, 10] results in [1, 2, 3, 4, 10].

inputFormat

The first line contains an integer n, representing the number of elements in the list. The second line contains n space-separated integers.

outputFormat

Output a single line containing the rearranged list as space-separated integers.

## sample
1
1
1

</p>