Stacks, Queues & Heaps
Linked List
When you see it
Signal words
If the prompt uses any of these, this pattern should come to mind first.
reverse listcyclemiddle nodenth from endmerge listsfast & slow
Practice
Drill this pattern with an AI trainer — reply only with Hint, Next, Lost, or paste your code.
Ask yourself
- Pointer surgery on nodes (reverse, reorder)?
- Cycle / middle → fast & slow pointers.
- A dummy head simplifies edge cases.
Classic problem
Reverse Linked List (LeetCode 206) — reverse a singly linked list and return the new
head. Walk forward, flipping each next pointer to point back at the node behind it.
Input: head = [1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1] — each node’s .next pointer is reversed in a single pass.
Common pitfalls
Losing the rest of the list by reassigning
.nexttoo early.
Null-deref on the final node.