Pattern · 12 problems
Linked List Interview Problems
Linked lists are pointer bookkeeping. I draw the nodes and say which pointer changes on each line.
Free: write the code and run it, no sign-up.
When I reach for it
- Nodes point to the next node, and you cannot index into the list.
- You must reverse, merge, reorder or remove a node.
- A cycle or the middle node comes up.
Problems, easiest first
4 easy · 6 medium · 2 hard. Open one to read it, then write it in the free editor.
- Linked List CycleeasyTwo Pointers
- Merge Two Sorted Listseasy
- Reverse Linked Listeasy
- Middle of the Linked ListeasyTwo Pointers
- Reorder ListmediumStackTwo Pointers
- Remove Nth Node From End of ListmediumTwo Pointers
- Copy List with Random PointermediumArrays & Hashing
- Design TwittermediumHeapsDesign
- LRU CachemediumDesignArrays & Hashing
- Add Two Numbersmedium
- Merge K Sorted ListshardHeaps
- Reverse Nodes in k-Grouphard
The idea
Pointers are the whole game. Before you code, draw three nodes. Then narrate each line: this pointer moves here, that link breaks there.
Two tools solve most of these. A dummy head removes the empty-list case. A fast pointer and a slow pointer find middles and cycles.
prev, curr = None, head
while curr:
nxt = curr.next # save the rest before you break the link
curr.next = prev # flip this node backward
prev, curr = curr, nxt
return prev # prev is the new headWhere it goes wrong
- Losing the rest of the list. Save next before you overwrite it.
- Skipping the empty list and the one-node list.
- A cycle in the input makes your loop run forever.
Say this before you type. Say which pointers you hold and which link you are about to change.
Where Coco comes in
Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit, and to talk with her for one hour. After that, talking comes with the $79 pack. Anyone can open the editor and run their code.
Questions people ask
- Why use a dummy head?
- It gives the first node a predecessor. Inserting or deleting at the head then needs no special case.
- How do fast and slow pointers find a cycle?
- The fast pointer takes two steps and the slow one takes one. In a cycle, the fast pointer eventually lands on the slow one.
Meet these next
Fin and Coco are characters, not people. strongyes.io is independent. Leo builds it with AI agents.
