week 4 of 15
Linked lists
Get comfortable with these coding mechanics first: a Node with value and next, saving next before overwriting it, a dummy node, loops like while cur and cur.next. Template to type from memory by the end of the week: reverse a list in place (prev, cur, next). Merge with a dummy node. Fast and slow pointers.
- 31Reverse Linked List (opens LeetCode in a new tab)Iterative pointer reversalEasy
- Common mistake
- Overwriting cur.next before saving it.
- 32Merge Two Sorted Lists (opens LeetCode in a new tab)Dummy nodeEasy
- Common mistake
- Forgetting to advance tail.
- 33Linked List Cycle (opens LeetCode in a new tab)Fast and slow pointersEasy
- Common mistake
- Missing the null checks on fast.next.
- 34Remove Nth Node From End of List (opens LeetCode in a new tab)Two pointers with a gapMedium
- Common mistake
- Removing the head node. The dummy node solves it.
- 35Reorder List (opens LeetCode in a new tab)Middle + reverse + weaveMedium
- Common mistake
- Not cutting the first half (mid.next = null) before weaving.
- 36Add Two Numbers (opens LeetCode in a new tab)Digit by digit with carryMedium
- Common mistake
- Dropping the final carry node.
- 37Copy List with Random Pointer (opens LeetCode in a new tab)Map old nodes to new nodesMedium
- Common mistake
- Forgetting that the random pointer can be null.
- 38LRU Cache (opens LeetCode in a new tab)Hash map + doubly linked listMedium
- Common mistake
- Forgetting to delete the evicted key from the map.
- 39Reverse Nodes in k-Group (opens LeetCode in a new tab)Group reversalHard
- Common mistake
- Reconnecting pointers between groups. Draw it first.