Linked List Pattern: Template + 75 LeetCode Problems

Rewire pointers in place, with a dummy head and a saved next to keep it safe.

  • 12 Easy
  • 56 Medium
  • 7 Hard
  • O(n) time

What the linked list pattern is

Linked list problems are pointer-rewiring exercises, and nearly all of the difficulty is in the edge cases rather than the algorithm. Two habits remove most of them. First, allocate a dummy node in front of the real head whenever the head itself might be deleted or replaced, so the head stops being a special case and the answer is always `dummy.next`. Second, before overwriting any `next`, save it — the reversal loop is exactly the three-step dance of saving the successor, redirecting the current node backwards, and stepping both cursors forward. The other half of the pattern is fast-and-slow pointers: advancing one cursor two nodes for every one of the other's finds the midpoint in a single pass, detects a cycle when the two meet, and locates the cycle's entry point when a third walk starts from the head. In-place work keeps the space at O(1), which is usually the actual constraint being tested.

When to use it

  • Nodes must be reordered, reversed, merged or removed without allocating a new list.
  • The head of the list can change — that is the dummy node's cue.
  • A cycle, a midpoint, or the nth node from the end is wanted in one pass.
  • The problem forbids converting the list to an array, which is otherwise always tempting.

The linked list template in Python

The shape, not a solution to any one problem. Adapt the condition and the summary being maintained; the skeleton stays the same across the 75 problems listed below.

Linked List — Python template
def reverse(head):
    previous = None
    node = head

    while node:
        following = node.next    # save it before the link is destroyed
        node.next = previous     # rewire backwards
        previous = node          # step both cursors forward
        node = following

    return previous              # the old tail is the new head

Complexity characteristics

Time
O(n)
Auxiliary space
O(1)

One pass, rewiring pointers as it goes. The constant space is the entire point of the pattern and is usually the constraint being tested — copying the list into an array makes almost all of these problems trivial at O(n) space, which is why the statement so often forbids it. Fast-and-slow pointers hold both figures: the midpoint, a cycle check and the nth node from the end each cost one pass and two pointers.

All 75 linked list LeetCode problems

Every problem in the library the linked list pattern applies to, grouped by LeetCode's own difficulty rating. 63 of the 75 carry a complete Python solution with a worked example and complexity analysis; the rest are listed for completeness, with the LeetCode Premium ones marked.

Related LeetCode topics

Easy (12)

#ProblemDifficultyTopics
21Merge Two Sorted ListsEasyRecursion, Linked List
83Remove Duplicates from Sorted ListEasyLinked List
141Linked List CycleEasyHash Table, Linked List, Two Pointers
160Intersection of Two Linked ListsEasyHash Table, Linked List, Two Pointers
203Remove Linked List ElementsEasyRecursion, Linked List
206Reverse Linked ListEasyRecursion, Linked List
234Palindrome Linked ListEasyStack, Recursion, Linked List +1
705Design HashSetEasyDesign, Array, Hash Table +2
706Design HashMapEasyDesign, Array, Hash Table +2
876Middle of the Linked ListEasyLinked List, Two Pointers
1290Convert Binary Number in a Linked List to IntegerEasyLinked List, Math
1474Delete N Nodes After M Nodes of a Linked ListPremiumEasyLinked List

Medium (56)

#ProblemDifficultyTopics
2Add Two NumbersMediumRecursion, Linked List, Math
19Remove Nth Node From End of ListMediumLinked List, Two Pointers
24Swap Nodes in PairsMediumRecursion, Linked List
61Rotate ListMediumLinked List, Two Pointers
82Remove Duplicates from Sorted List IIMediumLinked List, Two Pointers
86Partition ListMediumLinked List, Two Pointers
92Reverse Linked List IIMediumLinked List
109Convert Sorted List to Binary Search TreeMediumTree, Binary Search Tree, Linked List +2
114Flatten Binary Tree to Linked ListMediumStack, Tree, Depth-First Search +2
116Populating Next Right Pointers in Each NodeMediumTree, Depth-First Search, Breadth-First Search +2
117Populating Next Right Pointers in Each Node IIMediumTree, Depth-First Search, Breadth-First Search +2
138Copy List with Random PointerMediumHash Table, Linked List
142Linked List Cycle IIMediumHash Table, Linked List, Two Pointers
143Reorder ListMediumStack, Recursion, Linked List +1
146LRU CacheMediumDesign, Hash Table, Linked List +1
147Insertion Sort ListMediumLinked List, Sorting
148Sort ListMediumLinked List, Two Pointers, Divide and Conquer +2
237Delete Node in a Linked ListMediumLinked List
328Odd Even Linked ListMediumLinked List
355Design TwitterMediumDesign, Hash Table, Linked List +1
382Linked List Random NodeMediumReservoir Sampling, Linked List, Math +1
430Flatten a Multilevel Doubly Linked ListMediumDepth-First Search, Linked List, Doubly-Linked List
445Add Two Numbers IIMediumStack, Linked List, Math
622Design Circular QueueMediumDesign, Queue, Array +1
641Design Circular DequeMediumDesign, Queue, Array +1
707Design Linked ListMediumDesign, Linked List
725Split Linked List in PartsMediumLinked List
2095Delete the Middle Node of a Linked ListMediumLinked List, Two Pointers
2130Maximum Twin Sum of a Linked ListMediumStack, Linked List, Two Pointers
369Plus One Linked ListPremiumMediumLinked List, Math
379Design Phone DirectoryPremiumMediumDesign, Queue, Array +2
426Convert Binary Search Tree to Sorted Doubly Linked ListPremiumMediumStack, Tree, Depth-First Search +4
708Insert into a Sorted Circular Linked ListPremiumMediumLinked List
817Linked List ComponentsMediumArray, Hash Table, Linked List
1019Next Greater Node In Linked ListMediumStack, Array, Linked List +1
1171Remove Zero Sum Consecutive Nodes from Linked ListMediumHash Table, Linked List
1265Print Immutable Linked List in ReversePremiumMediumStack, Recursion, Linked List +1
1367Linked List in Binary TreeMediumTree, Depth-First Search, Linked List +1
1472Design Browser HistoryMediumStack, Design, Array +3
1634Add Two Polynomials Represented as Linked ListsPremiumMediumLinked List, Math, Two Pointers
1669Merge In Between Linked ListsMediumLinked List
1670Design Front Middle Back QueueMediumDesign, Queue, Array +2
1721Swapping Nodes in a Linked ListMediumLinked List, Two Pointers
1756Design Most Recently Used QueuePremiumMediumDesign, Array, Linked List +3
1797Design Authentication ManagerMediumDesign, Hash Table, Linked List +1
1836Remove Duplicates From an Unsorted Linked ListPremiumMediumHash Table, Linked List
2046Sort Linked List Already Sorted Using Absolute ValuesPremiumMediumLinked List, Two Pointers, Sorting
2058Find the Minimum and Maximum Number of Nodes Between Critical PointsMediumLinked List
2074Reverse Nodes in Even Length GroupsMediumLinked List
2181Merge Nodes in Between ZerosMediumLinked List, Simulation
2289Steps to Make Array Non-decreasingMediumStack, Array, Linked List +1
2326Spiral Matrix IVMediumArray, Linked List, Matrix +1
2487Remove Nodes From Linked ListMediumStack, Recursion, Linked List +1
2674Split a Circular Linked ListPremiumMediumLinked List, Two Pointers
2807Insert Greatest Common Divisors in Linked ListMediumLinked List, Math, Number Theory
2816Double a Number Represented as a Linked ListMediumStack, Linked List, Math

Hard (7)

#ProblemDifficultyTopics
23Merge k Sorted ListsHardLinked List, Divide and Conquer, Heap (Priority Queue) +1
25Reverse Nodes in k-GroupHardRecursion, Linked List
432All O`one Data StructureHardDesign, Hash Table, Linked List +1
460LFU CacheHardDesign, Hash Table, Linked List +1
716Max StackPremiumHardStack, Design, Linked List +2
1206Design SkiplistHardDesign, Linked List
2296Design a Text EditorHardStack, Design, Linked List +3

Related patterns

Problems sit in more than one pattern more often than not, and the overlap is where the interesting follow-up questions live.

Linked List pattern FAQ

What is the linked list pattern?

Linked list problems are pointer-rewiring exercises, and nearly all of the difficulty is in the edge cases rather than the algorithm. Two habits remove most of them.

How many LeetCode problems use the linked list pattern?

This page lists 75 LeetCode problems that the linked list pattern applies to: 12 Easy, 56 Medium and 7 Hard. 63 of them carry a complete Python solution with complexity analysis.

What is the time complexity of the linked list pattern?

O(n) time and O(1) space. One pass, rewiring pointers as it goes. The constant space is the entire point of the pattern and is usually the constraint being tested — copying the list into an array makes almost all of these problems trivial at O(n) space, which is why the statement so often forbids it. Fast-and-slow pointers hold both figures: the midpoint, a cycle check and the nth node from the end each cost one pass and two pointers.

When should I use the linked list pattern in an interview?

Nodes must be reordered, reversed, merged or removed without allocating a new list. The head of the list can change — that is the dummy node's cue.

Which linked list problem should I start with?

LeetCode 21. Merge Two Sorted Lists is the lowest-numbered Easy problem on this page, which makes it the usual starting point: the technique is visible without the problem's own complications getting in the way.

What patterns are related to linked list?

Two Pointers, Hash Map, Tree Traversal, Sorting. Problems frequently sit in more than one of these, and the overlap is where the interesting follow-up questions come from.

More ways in: all 22 patterns, the curated study lists, or the full problem list.

Meet the linked list problem you did not practise

Stealth Interview is a desktop app for macOS and Windows. It reads the coding problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer is saying — while staying invisible to screen sharing.