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
Create a dummy head node and a tail pointer. Compare the heads of both lists, attach the smaller node to tail, and advance that list pointer. When one list is exhausted, append the remaining nodes of the other.
Both input lists are already sorted. By always picking the smaller head node, the merged list maintains sorted order. The dummy node eliminates edge cases when the merged list is empty.
Updated Feb 2026