CT011

Alternating High-Low Chain

EasyAcceptance: 0.0%

The temple dancers of Codetikki move in alternating low-high-low-high rhythm. Given a linked list, rearrange the node values so they appear in alternating low -> high -> low -> high -> ... form. Input: first line n, second line n space-separated values. Output: the rearranged list as space-separated values.

Example 1:

Input: 5 1 2 3 4 5
Output: 1 3 2 5 4

Example 2:

Input: 4 4 3 2 1
Output: 3 4 1 2

Constraints:

1 <= n <= 10^4 -10^9 <= node value <= 10^9

Tags:

linked-list greedy
Loading...
Test Cases:No test cases
No test cases available.