Topic · 2 patterns
Linked Lists patterns
Linked-list questions are pointer surgery. Fast and slow pointers find the middle, a cycle or the k-th node from the end in one pass; in-place reversal rewires next pointers without extra memory. Draw the nodes before you code: most bugs are a pointer lost before it was saved.
The patterns
Fast & Slow Pointers
O(n) / O(1)
Move one pointer 1 step and another 2 steps; they meet inside a cycle, and slow lands on the middle when fast hits the end.
Spot it: Linked-list cycle or middle in one pass with O(1) space, or a chain x → f(x) that must repeat (Happy Number, Find the Duplicate).
In-place Reversal
O(n) / O(1)
Re-point next pointers one node at a time while carrying prev/curr; for k-groups, reverse a chunk then stitch.
Spot it: Reverse a whole list, a sublist [left, right], or every k nodes; reorder, rotate, swap pairs, palindrome check, in O(1) space.
Learn first: Fast & Slow Pointers
Which one? Match the signal
| If the problem says | Reach for |
|---|---|
| A linked list that might have a cycle, or you need the middle in one pass | Fast & Slow Pointers |
| Reverse a list, a sublist, or every k nodes — O(1) extra space | In-place LL Reversal |
Easy to confuse
Find the Duplicate Number looks like Cyclic Sort, but it’s Fast & Slow Pointers
Array must not be modified and O(1) space: values form a functional graph whose cycle entry is the duplicate.
Happy Number looks like Math / Number Theory, but it’s Fast & Slow Pointers
The question is whether an iterated function cycles; Floyd detects it without a set.
Used together
Fast & Slow Pointers + In-place Reversal
When: palindrome list, reorder list. Compare or interleave the halves with O(1) space.
Fast & Slow Pointers
- Middle of the Linked ListEasy
- Linked List CycleEasy
In-place Reversal
- Reverse Linked ListEasy
- Reverse Linked List IIMedium
Further reading
- Linked List explore cardLeetCode
Covers fast/slow pointers and reversal with hand-picked problems.
- Linked list cheatsheetTech Interview Handbook
Dummy node, two-pointer and reversal tricks with corner cases.
- Linked list visualizerVisuAlgo
Animate insert/delete/reverse to build pointer intuition.
- Cycle detection (Floyd/Brent)Wikipedia
Proof of why tortoise-hare finds the cycle start; asked as follow-up.
- NeetCode RoadmapNeetCode
Pattern-ordered problem tree with a short video per problem; best interview-first path.