Chapter 03 - Linked Lists

Every linked list problem is about rewiring pointers without losing a node. In Rust, it is also about ownership.

Coding Interview Patterns book cover with the Rust logo and a CHAP 03 label, the chapter on linked lists

This page is the entry point of chapter 3 of my Rust solutions to the book Coding Interview Patterns. It sums up the pattern in a few lines, then lists the problems of the chapter. As explained on the series page, the detailed explanations of the algorithms are in the book.

The idea

A linked list is a chain of nodes, each one pointing to the next. Reversing a list, removing a node or detecting an intersection all come down to changing a few next pointers in the right order. Two classic tricks: a dummy node in front of the head, which removes the special cases, and two pointers kept a fixed distance apart, which finds the kth node from the end in one pass.

The chapter also has an introduction page with my notes on the key ideas and a checklist.

When to reach for it

  • Reversal, removal, merging or reordering of nodes.
  • We need the kth node from the end, or the node where two lists meet.
  • A cache must evict the least recently used item: hash map plus doubly linked list (LRU cache).

In Rust

  • A singly linked list is usually Option<Box<ListNode>>. Option::take() moves a node out and leaves None behind: it is the key to most rewiring.
  • As soon as two owners point to the same node (doubly linked list, intersection), we need Rc<RefCell<Node>>, and Weak for back pointers.
  • Expect to fight the borrow checker here more than anywhere else in the book. It is normal, and instructive.

Problems in this chapter

Other chapters

All the chapters, with every problem, are listed on the series page.


Back to top

Published on: Dec 1 2026 at 10:00 AM | Last updated: Dec 1 2026 at 10:32 AM

Copyright © 1964-2026 - 40tude