Linked Lists — Complete Pattern Guide
Problems 206–250 · 45 posts · Easy × 10, Medium × 25, Hard × 10
Core Patterns
| # | Pattern | Key Idea | Problems |
|---|
| 1 | Reversal | prev/curr/next pointer dance | Reverse List, Reverse K-Group |
| 2 | Two Pointers (Fast/Slow) | Floyd's tortoise & hare | Cycle Detection, Middle, Nth from End |
| 3 | Merge | Compare heads, link smaller | Merge Two/K Sorted Lists |
| 4 | Dummy Head | Avoid edge cases at head | Remove Nth, Partition |
| 5 | In-Place Manipulation | Rewire pointers without extra space | Odd-Even, Rotate |
| 6 | Clone with Extra | HashMap or interleave trick | Copy List with Random Pointer |
| 7 | Design | Sentinel nodes + O(1) ops | LRU, LFU, Flatten |
Templates
Reverse a Linked List
def reverse(head):
prev = None
curr = head
while curr:
nxt = curr.next
curr.next = prev
prev = curr
curr = nxt
return prev
Fast / Slow Pointer
def find_middle(head):
slow = fast = head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
return slow
Detect Cycle
def has_cycle(head):
slow = fast = head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
if slow == fast: return True
return False
Merge Two Sorted Lists
def merge(l1, l2):
dummy = ListNode(0)
cur = dummy
while l1 and l2:
if l1.val <= l2.val: cur.next = l1; l1 = l1.next
else: cur.next = l2; l2 = l2.next
cur = cur.next
cur.next = l1 or l2
return dummy.next
Dummy Head Pattern
def remove_nth(head, n):
dummy = ListNode(0, head)
fast = slow = dummy
for _ in range(n+1): fast = fast.next
while fast:
fast = fast.next
slow = slow.next
slow.next = slow.next.next
return dummy.next
Problem Index — Linked Lists
🟢 Easy (206–215)
| # | Problem | Pattern |
|---|
| 206 | Reverse Linked List | Reversal |
| 207 | Middle of Linked List | Fast/Slow |
| 208 | Linked List Cycle | Fast/Slow |
| 209 | Merge Two Sorted Lists | Merge |
| 210 | Palindrome Linked List | Fast/Slow + Reverse |
| 211 | Remove Duplicates from Sorted List | Pointer Walk |
| 212 | Delete Node in Linked List | Copy + Delete |
| 213 | Intersection of Two Linked Lists | Two Pointers |
| 214 | Convert Binary Number to Integer | Bit Shift |
| 215 | Remove Linked List Elements | Dummy Head |
🟡 Medium (216–240)
| # | Problem | Pattern |
|---|
| 216 | Remove Nth Node From End | Dummy + Fast/Slow |
| 217 | Swap Nodes in Pairs | In-Place |
| 218 | Odd Even Linked List | In-Place |
| 219 | Rotate List | Find Length + Reconnect |
| 220 | Reorder List | Fast/Slow + Reverse + Merge |
| 221 | Add Two Numbers | Simulate Carry |
| 222 | Add Two Numbers II | Stack |
| 223 | Partition List | Two Dummy Heads |
| 224 | Sort List | Merge Sort |
| 225 | Delete Duplicates II (all dups) | Dummy Head |
| 226 | Copy List with Random Pointer | HashMap / Interleave |
| 227 | Flatten Multilevel Doubly Linked List | DFS / Stack |
| 228 | Insert into Sorted Circular List | Pointer Scan |
| 229 | Split Linked List in Parts | Even Split |
| 230 | Reverse Linked List II | Reversal |
| 231 | Swapping Nodes | Two Pointers |
| 232 | Remove Zero-Sum Sublists | Prefix Sum Map |
| 233 | Linked List Cycle II | Floyd's |
| 234 | Find the Duplicate Number | Floyd's on Array |
| 235 | Next Greater Node | Monotonic Stack |
| 236 | Design Linked List | Sentinel Design |
| 237 | Reverse Nodes in Even-Length Groups | Group Reversal |
| 238 | Delete the Middle Node | Fast/Slow |
| 239 | Maximum Twin Sum | Fast/Slow + Reverse |
| 240 | Merge Nodes In Between Zeros | Pointer Walk |
🔴 Hard (241–250)
| # | Problem | Pattern |
|---|
| 241 | Reverse Nodes in K-Group | Recursive Reversal |
| 242 | Merge K Sorted Lists | Heap / Divide & Conquer |
| 243 | LRU Cache (LL impl) | DLL + HashMap |
| 244 | Sort List (O(n log n) space O(1)) | Bottom-Up Merge Sort |
| 245 | Flatten Binary Tree to Linked List | Morris / DFS |
| 246 | Convert Sorted List to BST | Fast/Slow + Recursion |
| 247 | Linked List Components | HashSet |
| 248 | Insert into a Sorted Circular List | Edge Cases |
| 249 | All O'one (LL backbone) | DLL Buckets |
| 250 | Linked Lists Master Recap | Cheatsheet |