head. Number the nodes from one: the first node is at an odd position, the second at an even one, and so on.
Rearrange the list so that all nodes from odd positions come first, followed by all nodes from even positions. Within each group, nodes keep their original order. Return the head of the resulting list.
Try to use O(1) extra memory and O(n) time: relink the existing nodes instead of creating new ones.head=list_node([7, 3, 9, 1, 4, 8]) → [7, 9, 4, 3, 1, 8]
Positions 1, 3, 5 hold 7, 9, 4 and positions 2, 4, 6 hold 3, 1, 8. The first group goes first, then the second.
head=list_node([5, -2]) → [5, -2]
Two nodes are already in the right order.
head=list_node([]) → None
An empty list stays empty.
head=list_node([7, 3, 9, 1, 4, 8])
[7, 9, 4, 3, 1, 8]
Run checks the first 3 tests in your browser. Submit checks all 88 tests on the server, hidden ones included.