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.
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 headComplexity 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.
Easy (12)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 21 | Merge Two Sorted Lists | Easy | Recursion, Linked List |
| 83 | Remove Duplicates from Sorted List | Easy | Linked List |
| 141 | Linked List Cycle | Easy | Hash Table, Linked List, Two Pointers |
| 160 | Intersection of Two Linked Lists | Easy | Hash Table, Linked List, Two Pointers |
| 203 | Remove Linked List Elements | Easy | Recursion, Linked List |
| 206 | Reverse Linked List | Easy | Recursion, Linked List |
| 234 | Palindrome Linked List | Easy | Stack, Recursion, Linked List +1 |
| 705 | Design HashSet | Easy | Design, Array, Hash Table +2 |
| 706 | Design HashMap | Easy | Design, Array, Hash Table +2 |
| 876 | Middle of the Linked List | Easy | Linked List, Two Pointers |
| 1290 | Convert Binary Number in a Linked List to Integer | Easy | Linked List, Math |
| 1474 | Delete N Nodes After M Nodes of a Linked ListPremium | Easy | Linked List |
Medium (56)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 2 | Add Two Numbers | Medium | Recursion, Linked List, Math |
| 19 | Remove Nth Node From End of List | Medium | Linked List, Two Pointers |
| 24 | Swap Nodes in Pairs | Medium | Recursion, Linked List |
| 61 | Rotate List | Medium | Linked List, Two Pointers |
| 82 | Remove Duplicates from Sorted List II | Medium | Linked List, Two Pointers |
| 86 | Partition List | Medium | Linked List, Two Pointers |
| 92 | Reverse Linked List II | Medium | Linked List |
| 109 | Convert Sorted List to Binary Search Tree | Medium | Tree, Binary Search Tree, Linked List +2 |
| 114 | Flatten Binary Tree to Linked List | Medium | Stack, Tree, Depth-First Search +2 |
| 116 | Populating Next Right Pointers in Each Node | Medium | Tree, Depth-First Search, Breadth-First Search +2 |
| 117 | Populating Next Right Pointers in Each Node II | Medium | Tree, Depth-First Search, Breadth-First Search +2 |
| 138 | Copy List with Random Pointer | Medium | Hash Table, Linked List |
| 142 | Linked List Cycle II | Medium | Hash Table, Linked List, Two Pointers |
| 143 | Reorder List | Medium | Stack, Recursion, Linked List +1 |
| 146 | LRU Cache | Medium | Design, Hash Table, Linked List +1 |
| 147 | Insertion Sort List | Medium | Linked List, Sorting |
| 148 | Sort List | Medium | Linked List, Two Pointers, Divide and Conquer +2 |
| 237 | Delete Node in a Linked List | Medium | Linked List |
| 328 | Odd Even Linked List | Medium | Linked List |
| 355 | Design Twitter | Medium | Design, Hash Table, Linked List +1 |
| 382 | Linked List Random Node | Medium | Reservoir Sampling, Linked List, Math +1 |
| 430 | Flatten a Multilevel Doubly Linked List | Medium | Depth-First Search, Linked List, Doubly-Linked List |
| 445 | Add Two Numbers II | Medium | Stack, Linked List, Math |
| 622 | Design Circular Queue | Medium | Design, Queue, Array +1 |
| 641 | Design Circular Deque | Medium | Design, Queue, Array +1 |
| 707 | Design Linked List | Medium | Design, Linked List |
| 725 | Split Linked List in Parts | Medium | Linked List |
| 2095 | Delete the Middle Node of a Linked List | Medium | Linked List, Two Pointers |
| 2130 | Maximum Twin Sum of a Linked List | Medium | Stack, Linked List, Two Pointers |
| 369 | Plus One Linked ListPremium | Medium | Linked List, Math |
| 379 | Design Phone DirectoryPremium | Medium | Design, Queue, Array +2 |
| 426 | Convert Binary Search Tree to Sorted Doubly Linked ListPremium | Medium | Stack, Tree, Depth-First Search +4 |
| 708 | Insert into a Sorted Circular Linked ListPremium | Medium | Linked List |
| 817 | Linked List Components | Medium | Array, Hash Table, Linked List |
| 1019 | Next Greater Node In Linked List | Medium | Stack, Array, Linked List +1 |
| 1171 | Remove Zero Sum Consecutive Nodes from Linked List | Medium | Hash Table, Linked List |
| 1265 | Print Immutable Linked List in ReversePremium | Medium | Stack, Recursion, Linked List +1 |
| 1367 | Linked List in Binary Tree | Medium | Tree, Depth-First Search, Linked List +1 |
| 1472 | Design Browser History | Medium | Stack, Design, Array +3 |
| 1634 | Add Two Polynomials Represented as Linked ListsPremium | Medium | Linked List, Math, Two Pointers |
| 1669 | Merge In Between Linked Lists | Medium | Linked List |
| 1670 | Design Front Middle Back Queue | Medium | Design, Queue, Array +2 |
| 1721 | Swapping Nodes in a Linked List | Medium | Linked List, Two Pointers |
| 1756 | Design Most Recently Used QueuePremium | Medium | Design, Array, Linked List +3 |
| 1797 | Design Authentication Manager | Medium | Design, Hash Table, Linked List +1 |
| 1836 | Remove Duplicates From an Unsorted Linked ListPremium | Medium | Hash Table, Linked List |
| 2046 | Sort Linked List Already Sorted Using Absolute ValuesPremium | Medium | Linked List, Two Pointers, Sorting |
| 2058 | Find the Minimum and Maximum Number of Nodes Between Critical Points | Medium | Linked List |
| 2074 | Reverse Nodes in Even Length Groups | Medium | Linked List |
| 2181 | Merge Nodes in Between Zeros | Medium | Linked List, Simulation |
| 2289 | Steps to Make Array Non-decreasing | Medium | Stack, Array, Linked List +1 |
| 2326 | Spiral Matrix IV | Medium | Array, Linked List, Matrix +1 |
| 2487 | Remove Nodes From Linked List | Medium | Stack, Recursion, Linked List +1 |
| 2674 | Split a Circular Linked ListPremium | Medium | Linked List, Two Pointers |
| 2807 | Insert Greatest Common Divisors in Linked List | Medium | Linked List, Math, Number Theory |
| 2816 | Double a Number Represented as a Linked List | Medium | Stack, Linked List, Math |
Hard (7)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 23 | Merge k Sorted Lists | Hard | Linked List, Divide and Conquer, Heap (Priority Queue) +1 |
| 25 | Reverse Nodes in k-Group | Hard | Recursion, Linked List |
| 432 | All O`one Data Structure | Hard | Design, Hash Table, Linked List +1 |
| 460 | LFU Cache | Hard | Design, Hash Table, Linked List +1 |
| 716 | Max StackPremium | Hard | Stack, Design, Linked List +2 |
| 1206 | Design Skiplist | Hard | Design, Linked List |
| 2296 | Design a Text Editor | Hard | Stack, 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.