Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Three-step process: (1) find the middle node using slow/fast pointers, (2) reverse the second half of the list in place, (3) merge the two halves by alternating nodes from each. No extra space needed beyond pointers.
Finding the middle splits the list into two equal halves. Reversing the second half lets us pair the first node with the last, second with second-to-last, etc. Alternating merge weaves them into the required order.
Updated Feb 2026