Linked List Practice Problems
How to Use This Problem List
Linked list problems share a small number of underlying mechanics — pointer manipulation, two-pointer technique, and recursive decomposition. A student who has solved five "find the middle" variants does not struggle with the sixth because the pattern is the same.
Practice by pattern, not by difficulty label. An "easy" reversal problem and an "easy" cycle problem require completely different thinking. Grouping by pattern builds recognition speed — the ability to identify which pointer technique applies within the first two minutes of reading.
For each problem: spend three to five minutes identifying the pattern before touching code. The recognition clue column tells you exactly what phrase or constraint in the problem statement reveals the technique.
Pattern 1: Two Pointer — Slow and Fast
The slow pointer moves one step at a time; the fast pointer moves two steps. When fast reaches the end, slow is at a structurally useful position. This technique appears in cycle detection, finding the middle, and nth-from-end problems.
| Problem | Difficulty | Recognition Clue | Key Insight |
|---|---|---|---|
| Find Middle of Linked List | Easy | "middle node", "split in half" | When fast reaches null, slow is at the middle |
| Linked List Cycle | Easy | "cycle", "loop exists" | Fast and slow meet if and only if a cycle exists |
| Linked List Cycle II | Medium | "where does cycle begin" | After meeting point, reset one pointer to head — they meet at entry |
| Remove Nth Node From End | Medium | "nth from the end" | Advance fast n steps, then move both until fast.next is null |
| Middle of Linked List | Easy | "second middle if even" | Standard slow/fast — slow lands on second middle for even lists |
| Palindrome Linked List | Easy | "is it a palindrome" | Find middle, reverse second half, compare from both ends |
| Reorder List | Medium | "L0→Ln→L1→Ln-1..." | Find middle, reverse second half, merge alternately |
| Happy Number | Easy | "infinite loop possible" | Treat digit-sum sequence as a linked list — cycle detection |
Complexity target: O(n) time, O(1) space — both pointers traverse at most n steps each.
Recognition signal: the problem mentions "cycle," "middle," "nth from end," or involves a sequence that might loop. Any problem where you need to reach two positions simultaneously in one pass.
Pattern 2: Reversal
Reverse a list or a portion of it. The core operation is redirecting next pointers so they point backward. Mastering reversal unlocks palindrome checking, reordering, and k-group reversal.
| Problem | Difficulty | Recognition Clue | Key Insight |
|---|---|---|---|
| Reverse Linked List | Easy | "reverse the list" | Three pointers: prev=null, curr=head, next — iterate and redirect |
| Reverse Linked List II | Medium | "reverse from position m to n" | Find position m-1, reverse n-m+1 nodes, reconnect |
| Reverse Nodes in k-Group | Hard | "reverse every k nodes" | Check k nodes exist, reverse them, recurse on remainder |
| Palindrome Linked List | Easy | "is palindrome" | Reverse second half in-place, compare to first half |
| Swap Nodes in Pairs | Medium | "swap every two adjacent" | Reverse pairs iteratively — update prev.next after each swap |
| Rotate List | Medium | "rotate right by k places" | Find tail, make circular, break at (length - k % length) |
Complexity target: O(n) time, O(1) space for iterative reversal. O(n) space for recursive.
Recognition signal: the problem asks to rearrange the order of nodes. Any mention of "reverse," "palindrome," "rotate," or "reorder" is a reversal signal.
Pattern 3: Merge and Sort
Combine two or more sorted linked lists into one, or sort an unsorted list. The key insight: merging two sorted lists takes O(n + m) with two pointers advancing through each list.
| Problem | Difficulty | Recognition Clue | Key Insight |
|---|---|---|---|
| Merge Two Sorted Lists | Easy | "merge two sorted" | Compare heads, attach smaller, advance that pointer |
| Merge K Sorted Lists | Hard | "merge k sorted lists" | Divide and conquer — merge pairs recursively, O(n log k) |
| Sort List | Medium | "sort a linked list" | Merge sort — split at middle, sort each half, merge |
| Insertion Sort List | Medium | "insertion sort" | Maintain sorted prefix, insert each node in correct position |
| Add Two Numbers | Medium | "digits in reverse, return sum" | Traverse both lists, carry the overflow digit |
| Add Two Numbers II | Medium | "digits in forward order" | Use stacks to reverse, add with carry |
Complexity target: O(n log n) for sort, O(n + m) for merge of two lists, O(n log k) for k-way merge.
Recognition signal: "sorted," "merge," "combine," or the problem provides two or more lists that need combining. Also: any arithmetic problem where numbers are stored as linked lists.
Pattern 4: Remove Nodes
Delete specific nodes based on value, position, or condition. The pattern is always: find the node before the target, bypass the target.
| Problem | Difficulty | Recognition Clue | Key Insight |
|---|---|---|---|
| Remove Linked List Elements | Easy | "remove all occurrences of val" | Dummy head eliminates head-deletion special case |
| Remove Duplicates from Sorted List | Easy | "sorted, remove duplicates" | Skip curr.next while curr.next.val == curr.val |
| Remove Duplicates from Sorted List II | Medium | "remove ALL nodes with duplicates" | Dummy head + skip entire duplicate run |
| Remove Nth Node From End of List | Medium | "remove nth from end" | Two pointers n steps apart — stop when fast.next is null |
| Delete Node in a Linked List | Easy | "no access to head, delete given node" | Copy next node's value into curr, delete next node |
| Remove Zero Sum Consecutive Nodes | Medium | "remove nodes with consecutive sum = 0" | Prefix sum map — same sum means zero-sum sublist |
Complexity target: O(n) time, O(1) space for most removal problems.
Recognition signal: "remove," "delete," "eliminate." Key question: do you need to handle head deletion? If yes, use a dummy node.
Pattern 5: Intersection and Connection
Find where two linked lists meet, whether they share a tail, or connect structures together. These problems often involve length equalization or HashSet membership.
| Problem | Difficulty | Recognition Clue | Key Insight |
|---|---|---|---|
| Intersection of Two Linked Lists | Easy | "find the node where two lists intersect" | Equalize path lengths: walk both lists, switch to other list at end |
| Linked List Cycle II | Medium | "entry point of cycle" | Slow/fast meet, reset one to head, advance both one step at a time |
| Flatten a Multilevel Doubly Linked List | Medium | "flatten nested list" | DFS at each child node, connect tail to next, clear child pointer |
| Copy List with Random Pointer | Medium | "deep copy with random pointers" | HashMap original→copy for O(1) random pointer lookup |
| Insert into a Sorted Circular Linked List | Medium | "insert in sorted circular" | Four cases: wrap-around, normal, before head, empty list |
Complexity target: O(n + m) for intersection, O(n) for others. Space O(1) or O(n) depending on approach.
Recognition signal: "two lists," "intersection," "where do they meet," "share a tail." For copy problems: "random pointer" signals HashMap approach.
Pattern 6: Dummy Node Technique
Prepend a dummy (sentinel) node before the real head. This eliminates special-case handling for operations that affect the head — the dummy is always there, so no null checks needed for the predecessor.
| Problem | Difficulty | Recognition Clue | Key Insight |
|---|---|---|---|
| Remove Linked List Elements | Easy | "remove by value, head may be removed" | dummy.next = head; return dummy.next at end |
| Merge Two Sorted Lists | Easy | "merge while building result" | dummy tracks result tail — clean and no head special case |
| Remove Duplicates from Sorted List II | Medium | "delete ALL duplicate nodes" | Dummy allows deleting even the first node cleanly |
| Partition List | Medium | "all less than x before all ≥ x" | Two dummy nodes start two sub-lists, connect at end |
| Odd Even Linked List | Medium | "odd-indexed then even-indexed" | Two dummy heads, rebuild separately, connect |
| Reverse Nodes in k-Group | Hard | "reverse k nodes at a time" | Dummy before each group simplifies reconnection |
Complexity target: O(n) time, O(1) space.
Recognition signal: any deletion problem where the head might be removed. Any multi-pass construction problem where you build a new list node by node.
Template:
dummy = new Node(0) // sentinel before real head dummy.next = head prev = dummy curr = head // ... perform operations using prev and curr ... return dummy.next // real head of result
Pattern 7: Recursion
Decompose the linked list problem into the same problem on a smaller sublist. The base cases are null (empty list) and a single node. Recursion is natural for reversal, merge, and tree-like linked structures.
| Problem | Difficulty | Recognition Clue | Key Insight |
|---|---|---|---|
| Reverse Linked List | Easy | "can be done recursively" | reverse(head) = reverse(head.next) + head at end |
| Merge Two Sorted Lists | Easy | "recursive approach" | Return smaller head + merge(rest of smaller, other list) |
| Swap Nodes in Pairs | Medium | "swap pairs recursively" | swap first two, recurse on remainder |
| Reverse Nodes in k-Group | Hard | "reverse k nodes recursively" | Reverse first k, recurse on next group |
| Flatten Multilevel Doubly Linked List | Medium | "recursively flatten child lists" | Recurse into child, get tail, connect back to next |
| Linked List in Binary Tree | Medium | "does linked list exist as root-to-leaf path" | DFS with two-pointer on list and tree simultaneously |
Complexity target: O(n) time. O(n) space for the recursion stack — O(log n) for balanced tree recursion.
Recognition signal: the problem has overlapping substructure — solving the tail gives you what you need for the head. Or the problem explicitly says "can you do it recursively."
Pattern 8: Rearrangement and In-Place Modification
Reorder nodes without extra space — the list is restructured by pointer manipulation alone. No new nodes created, no values copied.
| Problem | Difficulty | Recognition Clue | Key Insight |
|---|---|---|---|
| Reorder List | Medium | "L0→Ln→L1→Ln-1" | Find middle, reverse second half, interleave merge |
| Odd Even Linked List | Medium | "odds first, then evens by position" | Two running pointers, weave odd-indexed into one chain |
| Partition List | Medium | "less than x before ≥ x, preserve order" | Two sub-lists, attach smaller-partition tail to larger head |
| Split Linked List in Parts | Medium | "split into k parts as evenly as possible" | Compute length, distribute extra nodes left-to-right |
| Rotate List | Medium | "rotate right by k" | Find tail and new tail, break and reattach |
| Swap Nodes in Pairs | Medium | "swap adjacent without changing values" | Redirect pointers, do not copy values |
Complexity target: O(n) time, O(1) space.
Recognition signal: "without extra space," "rearrange in-place," "do not change node values." Any reordering that explicitly disallows creating new nodes.
Recommended Study Order
Week 1 — Core Mechanics Pattern 1 (Slow/Fast): Find Middle, Detect Cycle, Remove Nth from End Pattern 2 (Reversal): Reverse Linked List (iterative + recursive) Week 2 — Building Blocks Pattern 4 (Remove): Remove Elements, Remove Duplicates, Remove Nth from End Pattern 6 (Dummy Node): Merge Two Sorted Lists, Remove Duplicates II Week 3 — Combination Problems Pattern 3 (Merge/Sort): Merge Two Sorted, Sort List, Add Two Numbers Pattern 5 (Intersection): Intersection of Two Lists, Copy List with Random Week 4 — Advanced Patterns Pattern 7 (Recursion): Reverse Nodes in k-Group, Merge K Sorted Lists Pattern 8 (Rearrangement): Reorder List, Odd Even Linked List, Partition List Revisit any patterns that felt unclear
Problem-Solving Checklist for Linked List Problems
Before writing code, run through this for every linked list problem:
1. What are the inputs and outputs? → Single list or multiple? → Return a node, a value, a boolean, or a new list? 2. Which pattern applies? → "middle" / "nth from end" / "cycle" → Slow/fast pointers → "reverse" / "palindrome" / "rotate" → Reversal → "merge" / "sorted" / "combine" → Merge technique → "remove" / "delete" / "eliminate" → Remove + dummy node → "intersect" / "where do they meet" → Equalize lengths or HashSet → "reorder" / "rearrange" → In-place rearrangement 3. Does the head node need special handling? → If the head might be deleted or changed → use a dummy node → If the head is always preserved → operate directly 4. Is the list singly or doubly linked? → Singly: no backward traversal, deletion needs trailing prev pointer → Doubly: temp.prev available, O(1) deletion at known node 5. Is the list circular? → Stop condition is temp == head, not temp == null → Do-while loop to visit head before checking condition 6. Edge cases to verify: → Empty list (head == null) → Single node → Two nodes (especially for swap, reversal, palindrome) → Cycle at head (cycle entry = head) → k > length (for k-group and rotate problems)
Difficulty Progression Reference
| Stage | Characteristics | Representative Problems |
|---|---|---|
| Foundation | Single traversal, one or two pointers, no structural change | Print list, find length, search by value |
| Early Intermediate | Single-pass with two pointers, basic dummy node | Detect cycle, find middle, remove duplicates |
| Intermediate | Combining two techniques (e.g., find middle + reverse) | Palindrome check, reorder list, remove nth from end |
| Late Intermediate | Multi-step algorithms, recursion, partial reversal | Reverse in k-group, flatten multilevel, sort list |
| Advanced | Multiple techniques combined, non-obvious reductions | Merge k sorted, copy with random pointer, LRU cache |
Common Interview Topics by Company Focus
Product-based companies (FAANG-tier):
- ›Reverse Linked List (always asked — know both iterative and recursive)
- ›Detect Cycle and Find Cycle Entry (Floyd's algorithm)
- ›Merge K Sorted Lists (tests divide and conquer thinking)
- ›LRU Cache (doubly linked list + HashMap — a system design staple)
- ›Copy List with Random Pointer (deep copy + identity tracking)
Service-based and on-campus:
- ›Reverse Linked List, Detect Cycle — appear in almost every interview
- ›Merge Two Sorted Lists — clean implementation matters
- ›Remove Duplicates from Sorted List
- ›Find Middle of Linked List
Startup and mid-size tech:
- ›Practical structural problems: partition list, odd-even separation
- ›Reorder List — tests command of multiple techniques
- ›Add Two Numbers — tests number handling in linked structure
Pointer Manipulation Quick Reference
The core operations that appear inside every linked list algorithm:
Advance a pointer: curr = curr.next Reverse a link: next = curr.next // save next before breaking link curr.next = prev // redirect backward prev = curr // advance prev curr = next // advance curr Insert after a node: newNode.next = curr.next curr.next = newNode Delete next node: curr.next = curr.next.next Two-pointer same speed (find middle): slow = slow.next fast = fast.next.next Two-pointer offset by k: // advance fast k times first // then advance both until fast.next is null // slow is now at (length - k)th node Detect cycle: slow = slow.next fast = fast.next.next if (slow == fast): cycle exists Find cycle entry (after meeting): reset slow to head advance both one step at a time when slow == fast: that is the entry node
Progress Tracking
After solving each problem, record:
- ›Pattern used — which of the 8 patterns above does this belong to?
- ›Recognition clue — what phrase or constraint in the problem pointed you to that pattern?
- ›Pointer technique — how many pointers? Slow/fast? Dummy? Trailing prev?
- ›Edge cases missed — empty list? Single node? k > length?
- ›Time to solve — target 20-25 minutes for medium problems under interview conditions
After 25-30 problems, you should recognize the pattern within two minutes of reading any new linked list problem. The specific signal: when you see the problem title, you can immediately name which pointer configuration solves it — before reading the details.
The goal is not to have memorized every solution. It is to understand which pointer arrangement solves which structural property, so any variation on a known pattern is immediately solvable.