Swap Nodes in PairsMedium

linked list recursion

Swap every two adjacent nodes and return the new head — by rewiring pointers, never touching the values. Two approaches: an iterative pass with a dummy head and a prev pointer, and a recursive decomposition that swaps each pair on the way back up.

Press play to swap the list in pairs.
Metrics
Legend
How it works
0 / 0