Swap Nodes in Pairs
Medium · Linked Lists · about 15 minutes
Asked at Bloomberg, Meta, Google, Amazon, Microsoft.
Walk the list two nodes at a time and exchange each pair (1st with 2nd, 3rd with 4th, …), relinking the nodes rather than swapping their values. If one node is left over at the end, it stays put. Return the new head.