const solve = (nums) => { let left = 0, right = nums.length - 1; while (left < right) { const sum = nums[left] + nums[right]; if (sum === target) return [left, right]; }}
Patterns

Linked List Patterns for LeetCode Interviews

Linked list problems test pointer manipulation skills — master the 5 core patterns and you can solve any linked list question on LeetCode.

10 min read|

Linked list problems are pointer manipulation puzzles

5 core patterns that cover every linked list interview question

Linked Lists Are a Pointer Manipulation Playground

Linked lists are one of the most popular data structures in coding interviews, and for good reason. They test your ability to manipulate pointers, handle edge cases, and think carefully about references — skills that translate directly to real-world engineering. If you have ever debugged a null pointer exception in production, you already know why interviewers care about this.

Unlike arrays, linked lists force you to think about how data connects rather than where data lives. There is no random access, no convenient index. Every operation requires walking the chain node by node, updating next pointers without losing your place. That constraint is exactly what makes leetcode linked list problems so revealing in an interview setting.

The good news is that linked list interview questions follow a small number of recurring patterns. Master five core techniques — reversal, fast and slow pointers, merge, the dummy head trick, and systematic edge case handling — and you can confidently tackle any linked list problem that appears on LeetCode or in a live interview.

Linked List Fundamentals You Need to Know

Before diving into patterns, make sure the fundamentals are rock solid. A singly linked list is a chain of nodes where each node holds a value and a next pointer. A doubly linked list adds a prev pointer, allowing traversal in both directions. Most interview problems use singly linked lists because the constraint of one-directional traversal creates more interesting challenges.

Traversal is the foundation of every linked list operation. You start at the head and follow next pointers until you reach null. The key discipline is never losing your reference to the current node or the nodes you still need. A single careless reassignment can disconnect the entire chain.

The dummy head technique is one of the most valuable tricks for linked list problems. When the head of the list might change — during deletion, insertion, or reordering — create a dummy node that points to the head. Work with the dummy, then return dummy.next as the new head. This eliminates the need for special-case handling when the first node is affected.

  • Singly linked list: each node has val and next — O(n) traversal, O(1) insert/delete at known position
  • Doubly linked list: each node has val, next, and prev — used in LRU Cache (#146) and similar problems
  • Dummy head: create a sentinel node before the real head to simplify edge cases
  • Always track your pointers: current, previous, and next-to-process before any reassignment
  • Time complexity: most linked list operations are O(n) since you must traverse to find the target position

Reverse a Linked List — The Most Tested Pattern

If you learn one linked list pattern, make it reversal. Reverse Linked List (#206) is the single most frequently asked linked list problem — it appears at Amazon, Google, Microsoft, and Meta. The iterative approach uses three pointers: prev (starts as null), curr (starts at head), and next (saved before each reassignment). At each step, you save curr.next, point curr.next to prev, advance prev to curr, and advance curr to the saved next. After the loop, prev is the new head.

The recursive approach is elegant but harder to reason about during an interview. The base case is when you reach the end of the list (curr is null or curr.next is null). On the way back up the call stack, you reverse each pointer: curr.next.next = curr, then set curr.next = null. The recursion naturally processes the list from tail to head.

Reverse Linked List II (#92) raises the difficulty by asking you to reverse only a sublist between positions left and right. This requires finding the node just before the sublist, reversing exactly the right number of nodes, and reconnecting both ends. The dummy head technique is essential here because the reversal might start at position 1, changing the head of the list.

Practice the iterative reverse until you can write it in under two minutes with no bugs. It is the building block for dozens of harder linked list problems, including Reverse Nodes in k-Group (#25) and Palindrome Linked List (#234).

💡

Pro Tip

Always use a dummy head node when the head of the list might change — it eliminates edge cases and makes your code cleaner.

Fast & Slow Pointers for Linked List Problems

The fast and slow pointer technique — also called the tortoise and hare algorithm — is the go-to pattern for cycle detection and finding the middle of a linked list. Two pointers start at the head. The slow pointer moves one step at a time, the fast pointer moves two steps. If there is a cycle, they will eventually meet. If there is no cycle, the fast pointer reaches null.

Linked List Cycle (#141) is the classic application. Initialize slow and fast to head. In each iteration, move slow one step and fast two steps. If fast or fast.next is null, there is no cycle. If slow equals fast, you have found the cycle. This runs in O(n) time and O(1) space — far better than the hash set approach that uses O(n) extra memory.

Linked List Cycle II (#142) takes it further by asking where the cycle begins. After detecting the cycle (slow meets fast), reset one pointer to head and keep the other at the meeting point. Move both one step at a time — they will meet at the cycle entrance. The mathematical proof relies on the fact that the distance from head to cycle start equals the distance from meeting point to cycle start when traversing the cycle.

Middle of the Linked List (#876) uses the same two-pointer setup without cycles. When fast reaches the end, slow is at the middle. This is used as a building block in problems like Sort List (#148) where you need to split the list in half for merge sort, and Palindrome Linked List (#234) where you reverse the second half and compare.

  • #141 Linked List Cycle — detect cycle in O(1) space with fast and slow pointers
  • #142 Linked List Cycle II — find the cycle entrance node using the mathematical reset trick
  • #876 Middle of the Linked List — slow pointer lands on the middle when fast reaches the end
  • #234 Palindrome Linked List — find middle, reverse second half, compare both halves

Merge and Sort Linked List Patterns

Merge Two Sorted Lists (#21) is a fundamental linked list problem that teaches the merge technique you will reuse in harder problems. Create a dummy head, then compare the current nodes of both lists. Append the smaller node to the merged list and advance that pointer. When one list is exhausted, append the remainder of the other. Return dummy.next.

Sort List (#148) combines two patterns: find the middle using fast and slow pointers, then recursively split and merge. This is essentially merge sort adapted for linked lists. The beauty is that linked lists support O(1) split and merge operations — no extra array needed — making this an elegant O(n log n) sort with O(log n) recursion stack space.

Merge k Sorted Lists (#23) extends the two-list merge to k lists. The brute force approach merges lists one by one in O(nk) time. The optimal approach uses a min-heap (priority queue) of size k to always pick the smallest available node in O(log k) time, giving O(n log k) total. Alternatively, you can use divide and conquer: pair up lists and merge each pair, reducing k lists to k/2, then k/4, and so on.

These merge problems illustrate how linked list techniques compose. The dummy head, the two-pointer merge, and the fast-slow split are all building blocks that combine to solve increasingly complex problems.

  • #21 Merge Two Sorted Lists — the foundational merge with dummy head technique
  • #148 Sort List — merge sort on linked lists using fast/slow split and recursive merge
  • #23 Merge k Sorted Lists — min-heap or divide-and-conquer for O(n log k) merging
  • #2 Add Two Numbers — process two lists in parallel with a carry, similar merge structure
⚠️

Watch Out

The most common linked list bug is losing a reference — always save node.next before overwriting it during reversal or reordering.

Common Linked List Mistakes That Cost You the Interview

The most common linked list bug is losing a reference. When you write curr.next = someOtherNode, the original next node is gone unless you saved it first. This happens constantly during reversal, reordering, and deletion. Before overwriting any next pointer, always save the reference you are about to lose: let saved = curr.next before curr.next = prev.

Forgetting edge cases is the second biggest killer. Empty lists (head is null), single-node lists (head.next is null), and two-node lists all behave differently from the general case. Always test your solution mentally against these three inputs before declaring it correct. The dummy head technique eliminates many of these edge cases, but you still need to handle null input explicitly.

Not using dummy heads when the head might change is a subtle but costly mistake. Problems like Remove Nth Node From End (#19), Swap Nodes in Pairs (#24), and Partition List (#86) can all modify the first node. Without a dummy, you need special-case code for head deletion that is easy to get wrong under pressure.

Finally, watch for off-by-one errors when counting positions. If a problem says "the kth node from the end," clarify whether it is 0-indexed or 1-indexed. Use two pointers with a gap of k (or k+1 depending on indexing) to find the target in a single pass.

Building Linked List Intuition with YeetCode Flashcards

Linked list problems reward consistent, spaced practice more than marathon grinding sessions. The pointer logic needs to become second nature — you should be able to reverse a linked list, detect a cycle, and merge two sorted lists without thinking about the mechanics. That level of fluency comes from reviewing the patterns at increasing intervals.

Start with Reverse Linked List (#206) and Merge Two Sorted Lists (#21) — these two problems contain the core pointer manipulation techniques that every other linked list problem builds on. Once those are automatic, move to Linked List Cycle (#141) and Middle of the Linked List (#876) to master the fast and slow pointer pattern. Then tackle the harder variants: Reverse Linked List II (#92), Sort List (#148), and Merge k Sorted Lists (#23).

YeetCode flashcards break each leetcode linked list problem into pattern recognition cards. Instead of memorizing code line by line, you train yourself to identify which pattern applies, recall the key pointer setup, and remember the edge cases. Spaced repetition schedules reviews right before you would forget, building the deep recall that holds up under interview pressure.

The goal is not to have every solution memorized. It is to see a new linked list problem in an interview and immediately recognize which of the five core patterns applies — reversal, fast/slow, merge, dummy head, or a combination. That pattern recognition is what separates candidates who solve linked list problems in ten minutes from those who struggle for thirty.

ℹ️

Did You Know

Reverse Linked List (#206) is the single most frequently asked linked list problem — it appears at Amazon, Google, Microsoft, and Meta.

Ready to master algorithm patterns?

YeetCode flashcards help you build pattern recognition through active recall and spaced repetition.

Start practicing now