values, with positions counted from zero. The numbers at even positions (0, 2, 4, …) and at odd positions (1, 3, 5, …) are handled separately:
- sort the numbers at even positions in non-decreasing order;
- sort the numbers at odd positions in non-increasing order.
A number never moves from an even position to an odd one or the other way round. Return the resulting array.values=[9, 2, 4, 6, 1, 3] → [1, 6, 4, 3, 9, 2]
The even positions hold 9, 4, 1, which ascending is 1, 4, 9. The odd positions hold 2, 6, 3, which descending is 6, 3, 2. Together: [1, 6, 4, 3, 9, 2].
values=[5, 5, 2] → [2, 5, 5]
On the even positions 5 and 2 swap. The only odd position keeps its number.
values=[9, 2, 4, 6, 1, 3]
[1, 6, 4, 3, 9, 2]
Run checks the first 3 tests in your browser. Submit checks all 89 tests on the server, hidden ones included.