#K37802. Wave Array Transformation
Wave Array Transformation
Wave Array Transformation
Given an array of integers, your task is to transform the array into a wave form. The wave form is defined as follows: for every even index i (0-indexed), the element at that index should be greater than or equal to its adjacent elements. Formally, for every even index \( i \):
\( a_i \geq a_{i-1} \) if \( i - 1 \) exists, and \( a_i \geq a_{i+1} \) if \( i + 1 \) exists.
You need to perform this transformation in-place and output the resulting array.
inputFormat
The first line of input contains a single integer \( N \) representing the number of elements in the array. The second line contains \( N \) space-separated integers representing the elements of the array.
outputFormat
Output a single line containing \( N \) space-separated integers representing the transformed wave array.
## sample6
3 6 5 10 7 20
6 3 10 5 20 7