DSA Tutorial
🔍

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.

ProblemDifficultyRecognition ClueKey Insight
Find Middle of Linked ListEasy"middle node", "split in half"When fast reaches null, slow is at the middle
Linked List CycleEasy"cycle", "loop exists"Fast and slow meet if and only if a cycle exists
Linked List Cycle IIMedium"where does cycle begin"After meeting point, reset one pointer to head — they meet at entry
Remove Nth Node From EndMedium"nth from the end"Advance fast n steps, then move both until fast.next is null
Middle of Linked ListEasy"second middle if even"Standard slow/fast — slow lands on second middle for even lists
Palindrome Linked ListEasy"is it a palindrome"Find middle, reverse second half, compare from both ends
Reorder ListMedium"L0→Ln→L1→Ln-1..."Find middle, reverse second half, merge alternately
Happy NumberEasy"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.

ProblemDifficultyRecognition ClueKey Insight
Reverse Linked ListEasy"reverse the list"Three pointers: prev=null, curr=head, next — iterate and redirect
Reverse Linked List IIMedium"reverse from position m to n"Find position m-1, reverse n-m+1 nodes, reconnect
Reverse Nodes in k-GroupHard"reverse every k nodes"Check k nodes exist, reverse them, recurse on remainder
Palindrome Linked ListEasy"is palindrome"Reverse second half in-place, compare to first half
Swap Nodes in PairsMedium"swap every two adjacent"Reverse pairs iteratively — update prev.next after each swap
Rotate ListMedium"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.

ProblemDifficultyRecognition ClueKey Insight
Merge Two Sorted ListsEasy"merge two sorted"Compare heads, attach smaller, advance that pointer
Merge K Sorted ListsHard"merge k sorted lists"Divide and conquer — merge pairs recursively, O(n log k)
Sort ListMedium"sort a linked list"Merge sort — split at middle, sort each half, merge
Insertion Sort ListMedium"insertion sort"Maintain sorted prefix, insert each node in correct position
Add Two NumbersMedium"digits in reverse, return sum"Traverse both lists, carry the overflow digit
Add Two Numbers IIMedium"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.

ProblemDifficultyRecognition ClueKey Insight
Remove Linked List ElementsEasy"remove all occurrences of val"Dummy head eliminates head-deletion special case
Remove Duplicates from Sorted ListEasy"sorted, remove duplicates"Skip curr.next while curr.next.val == curr.val
Remove Duplicates from Sorted List IIMedium"remove ALL nodes with duplicates"Dummy head + skip entire duplicate run
Remove Nth Node From End of ListMedium"remove nth from end"Two pointers n steps apart — stop when fast.next is null
Delete Node in a Linked ListEasy"no access to head, delete given node"Copy next node's value into curr, delete next node
Remove Zero Sum Consecutive NodesMedium"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.

ProblemDifficultyRecognition ClueKey Insight
Intersection of Two Linked ListsEasy"find the node where two lists intersect"Equalize path lengths: walk both lists, switch to other list at end
Linked List Cycle IIMedium"entry point of cycle"Slow/fast meet, reset one to head, advance both one step at a time
Flatten a Multilevel Doubly Linked ListMedium"flatten nested list"DFS at each child node, connect tail to next, clear child pointer
Copy List with Random PointerMedium"deep copy with random pointers"HashMap original→copy for O(1) random pointer lookup
Insert into a Sorted Circular Linked ListMedium"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.

ProblemDifficultyRecognition ClueKey Insight
Remove Linked List ElementsEasy"remove by value, head may be removed"dummy.next = head; return dummy.next at end
Merge Two Sorted ListsEasy"merge while building result"dummy tracks result tail — clean and no head special case
Remove Duplicates from Sorted List IIMedium"delete ALL duplicate nodes"Dummy allows deleting even the first node cleanly
Partition ListMedium"all less than x before all ≥ x"Two dummy nodes start two sub-lists, connect at end
Odd Even Linked ListMedium"odd-indexed then even-indexed"Two dummy heads, rebuild separately, connect
Reverse Nodes in k-GroupHard"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.

ProblemDifficultyRecognition ClueKey Insight
Reverse Linked ListEasy"can be done recursively"reverse(head) = reverse(head.next) + head at end
Merge Two Sorted ListsEasy"recursive approach"Return smaller head + merge(rest of smaller, other list)
Swap Nodes in PairsMedium"swap pairs recursively"swap first two, recurse on remainder
Reverse Nodes in k-GroupHard"reverse k nodes recursively"Reverse first k, recurse on next group
Flatten Multilevel Doubly Linked ListMedium"recursively flatten child lists"Recurse into child, get tail, connect back to next
Linked List in Binary TreeMedium"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.

ProblemDifficultyRecognition ClueKey Insight
Reorder ListMedium"L0→Ln→L1→Ln-1"Find middle, reverse second half, interleave merge
Odd Even Linked ListMedium"odds first, then evens by position"Two running pointers, weave odd-indexed into one chain
Partition ListMedium"less than x before ≥ x, preserve order"Two sub-lists, attach smaller-partition tail to larger head
Split Linked List in PartsMedium"split into k parts as evenly as possible"Compute length, distribute extra nodes left-to-right
Rotate ListMedium"rotate right by k"Find tail and new tail, break and reattach
Swap Nodes in PairsMedium"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

StageCharacteristicsRepresentative Problems
FoundationSingle traversal, one or two pointers, no structural changePrint list, find length, search by value
Early IntermediateSingle-pass with two pointers, basic dummy nodeDetect cycle, find middle, remove duplicates
IntermediateCombining two techniques (e.g., find middle + reverse)Palindrome check, reorder list, remove nth from end
Late IntermediateMulti-step algorithms, recursion, partial reversalReverse in k-group, flatten multilevel, sort list
AdvancedMultiple techniques combined, non-obvious reductionsMerge 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:

  1. Pattern used — which of the 8 patterns above does this belong to?
  2. Recognition clue — what phrase or constraint in the problem pointed you to that pattern?
  3. Pointer technique — how many pointers? Slow/fast? Dummy? Trailing prev?
  4. Edge cases missed — empty list? Single node? k > length?
  5. 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.

Linked List Practice Problems