Loading...
Loading...
Loading...
Rearrange a linked list so that all nodes at odd positions (1st, 3rd, 5th, ...) come first, followed by all nodes at even positions. Keep the order inside each group. Print the list.
Example
Input
1 2 3 4 5 6
Output
1 3 5 2 4 6
Try the problem first. Open one hint at a time.
Keep one pointer for odd nodes and one for even nodes, and remember where the even group starts.
At the end, link the last odd node to the first even node.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor