Skip to content
Skilled.dev

Linked Lists | Coding Interview Data Structure

Understand linked-list structure, traversal costs, and the pointer relationships behind insertion, deletion, and reversal.

13:19 · Trey Huffine · Published 2025-10-15

Watch on YouTube · Read lesson notes · Open the current lesson

Chapters

  1. 0:00 Introduction
  2. 0:12 Linked Lists Explained
  3. 2:53 Real-World Analogy (Trains)
  4. 3:24 Singly vs. Doubly Linked Lists
  5. 5:24 Code Example of a Linked List
  6. 6:13 Linked Lists vs. Arrays
  7. 7:05 Big O
  8. 8:52 Pros and Cons
  9. 10:12 Linked Lists in Real Life
  10. 11:45 Linked Lists in Interviews

Selected start: 0:00. Press play in the video to watch.

Changes since recording

  • A blockchain links each block only to the block before it, not in both directions.

Use the current lesson code when checking behavior.

Lesson notes

These notes explain the problem and current implementation. They are a reading companion, not a verbatim transcript of the recording.

A linked list stores a sequence through nodes that refer to other nodes. A singly linked node points to its successor; a doubly linked node also points to its predecessor. The recording compares those links with array indexes. For interview problems, the first question is often what references the function receives: only a head, a head and tail, or a complete wrapper object.

Separate reaching a node from changing its links

If you already have a predecessor, inserting after it needs a small number of reference changes. Finding the predecessor by position may require a linear walk from the head. Describing insertion as constant time without naming the available reference hides that search cost.

Appending has the same distinction. A singly linked list with only its head must walk to the end. A wrapper that retains a tail can append directly, provided it also updates the empty-list case. Removing the tail from a singly linked list still needs its predecessor unless that reference is available separately.

Preserve the rest of the chain

When changing a next reference, keep access to any nodes you still need. Reversal is a useful example: save the old successor before pointing the current node backward. Otherwise, the remaining chain may become unreachable from the function's local references.

A function that prepends, removes the head, or reverses the list may return a different head. Callers must use that returned reference. Matching node values is also different from matching node identity; two nodes may contain equal data while occupying different positions in the chain.

Test structural boundaries

Use an empty list, one node, and two nodes before testing a long example. Check that the last next reference is empty and that any wrapper's length agrees with a full traversal. For a doubly linked list, walking backward should recover the same nodes in reverse order. Accidental cycles can make a simple traversal run forever.

The blockchain comparison in the recording is an analogy for backward links; it does not imply that ordinary blocks form a doubly linked list. Continue with Pointers for reference identity, Implement a Linked List for mutations, and the pointer visualizer for a step-by-step reversal trace.

More in Linked Lists