← All patterns
10 / 29
Stacks, Queues & Heaps

Linked List

🚂
Picture this

A train of carriages stretches down the corridor; you can only walk forward, car to coupled car.

When you see it

Signal words

If the prompt uses any of these, this pattern should come to mind first.

reverse listcyclemiddle nodenth from endmerge listsfast & slow

Ask yourself

  1. Pointer surgery on nodes (reverse, reorder)?
  2. Cycle / middle → fast & slow pointers.
  3. A dummy head simplifies edge cases.

Canonical template

let prev: ListNode | null = null;
let cur = head;
while (cur) {
  const next = cur.next;
  cur.next = prev;
  prev = cur;
  cur = next;
}
return prev;

Common pitfalls

Losing the rest of the list by reassigning .next too early.

Null-deref on the final node.