Loading...
Loading...
Loading...
Reorder a linked list L0, L1, ..., Ln into L0, Ln, L1, Ln-1, L2, Ln-2, and so on, by changing links only. Print the result.
Example 1
Input
1 2 3 4 5
Output
1 5 2 4 3
Example 2
Input
1 2 3 4
Output
1 4 2 3
Try the problem first. Open one hint at a time.
Find the middle, cut the list in two and reverse the second half.
Then weave the two halves together one node at a time.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor