#C10196. Zigzag Array Conversion

    ID: 39374 Type: Default 1000ms 256MiB

Zigzag Array Conversion

Zigzag Array Conversion

Given an array of integers, rearrange its elements into a zigzag order such that: [ a_1 < a_2 > a_3 < a_4 > a_5 < \cdots ] In other words, after the transformation, the first element should be less than the second, the second should be greater than the third, the third less than the fourth, and so on. This pattern is defined for a 1-indexed array. You are required to process the input in a single test case via standard input and print the rearranged array using standard output with elements separated by a single space.

For example, if the input array is [4, 3, 7, 8, 6, 2, 1], the correct zigzag order will be [3, 7, 4, 8, 2, 6, 1].

inputFormat

The first line contains an integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers denoting the elements of the array.

outputFormat

Output the array after rearranging it into zigzag order. The elements should be printed in one line separated by a single space.## sample

7
4 3 7 8 6 2 1
3 7 4 8 2 6 1

</p>