Stage 1 · Code
Linked Lists & Trees
Linked List Manipulation
Reverse, merge, detect cycles, and find the middle — four pointer techniques that unlock 80% of linked-list interview problems.
The Pattern
Most linked-list problems reduce to a handful of pointer-manipulation techniques. Since you cannot index into a list in O(1), you reposition pointers — often two at a time — to reverse subsequences, find midpoints, or detect cycles. These techniques share a common skeleton: advance pointers, rewire links, repeat until a condition is met.
Manipulation problems modify the arrows between nodes — reversing direction, merging two chains, or chasing a cycle with a fast pointer.
Template Code
When to Use
- Reverse a sublist: prev/curr/next triple-pointer technique (O(n), O(1)).
- Merge two sorted lists: dummy head + compare-and-append loop (O(n+m), O(1)).
- Detect a cycle: Floyd's tortoise-and-hare — slow + fast pointer meet (O(n), O(1)).
- Find middle / remove nth from end: offset slow/fast pointers by n steps.
- Palindrome check: find middle → reverse second half → compare halves.
The most common linked-list bug is losing a reference. Always save the next pointer before overwriting a link. Draw the pointer diagram for each iteration until the pattern becomes automatic.
Problems
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.