Pattern

Linked lists

Rewire next (and sometimes random) pointers directly, using runner pointers instead of copying into an array.

What it is

Linked-list problems are about manipulating pointers rather than values: reversing, splicing, or reordering nodes by changing what each node's next points to, usually with the constraint that you reuse existing nodes instead of building a new list. The recurring tools are a small number of pointers moving through the list at different speeds or from different starting points — a slow/fast pair to find a midpoint or detect a cycle, two pointers offset by a fixed gap to find a position from the end, or a dummy head node to avoid special-casing the first element.

When it applies

Tells in the problem

The classic mistake

Losing the rest of the list by overwriting a node's next pointer before the pointer that was about to be replaced has been saved somewhere else — reversal is the classic site of this bug, where advancing to the next node after rewiring current.next leaves you unable to continue because the original next node is gone. The general fix is to always capture the node you're about to lose (next_node = current.next) before you touch any pointer on current, and to reach for a dummy head node whenever the operation might change what the first node of the result is, so the head case doesn't need separate logic from every other case.

Questions to start with

All 8 linked lists questions

Problem statement, examples and hints are free on every page; the worked approach, solution and tests are in the company guides.

Free starter pack

13 must-tier questions with full solutions

Sign in with an email — no purchase — and read them in the full reader.

No password, no spam. One sign-in email; you can read the pack in the full reader.