4 patterns · 20 problems
Linked List
Pointer choreography — fast/slow runners, dummy heads, recursion, and in-place reversal.
Each pattern below starts with when to reach for it and the clue in the prompt that gives it away. Then it runs on real problems: pick one to watch the technique step by step, open its full solution, or practise it on an original problem with graded tests.
01Pattern
Fast and Slow Pointers
Two runners at different speeds expose cycles and midpoints.
O(1) spacenaïve O(n) spaceWhen to reach for it
- You have a problem where you need to find pairs of elements that meet certain conditions, such as the midpoint of the linked list, detecting cycles, or removing specific elements.
Spot it in the prompt
Look for problems that involve traversing the linked list efficiently using two pointers simultaneously, often requiring pointer manipulation or comparison.
Linked List Cycle
How to solve it
Move slow by one and fast by two; if they ever meet a cycle exists, otherwise fast reaches null.
02Pattern
Dummy Node Technique
A placeholder head erases messy edge cases.
When to reach for it
- You need to simplify edge cases, such as handling an empty list or adding/removing elements at the beginning.
Spot it in the prompt
Problems often involve scenarios where dealing with the head of the linked list is cumbersome or requires special treatment.
Add Two Numbers
How to solve it
Animation shows the Dummy Node Technique techniqueTraverse both lists adding digits plus carry, appending each sum node after a dummy head to simplify list construction.
Odometer Tape Sum is our own problem on the same technique: a new statement, graded in your browser.
03Pattern
Recursion Technique
Let the call stack walk the list for you.
When to reach for it
- Solving problems that require traversal or manipulation of the linked list structure in a recursive manner.
Spot it in the prompt
Look for problems where a recursive approach provides an elegant solution, such as dividing it into subproblems.
Swap Nodes in Pairs
How to solve it
Animation shows the Recursion Technique techniqueRecursively swap the first two nodes, then point the first at the result of swapping the remaining list.
Swap Neighbouring Clips is our own problem on the same technique: a new statement, graded in your browser.
04Pattern
In-Place Reversal Technique
Rewire next pointers to reverse without extra space.
O(1) spacenaïve O(n) spaceWhen to reach for it
- You need to reverse the linked list in-place without using extra space, typically by modifying the pointers iteratively.
Spot it in the prompt
Problems where you're asked to reverse the linked list or perform operations on segments without using additional data structures.
Reverse Linked List
How to solve it
Animation shows the In-Place Reversal Technique techniqueIterate with prev, curr, and next pointers, redirecting each node's next to prev and advancing until the list is reversed.
Rewind the Telemetry Chain is our own problem on the same technique: a new statement, graded in your browser.
After the pattern
Now solve one you haven't seen.
Reading a pattern isn't the same as using it. The practice set has 1,194 original problems on the same techniques, each graded in your browser.
1,194 problems · 15,062 graded tests · free