knaxuslearn · build · ship

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.

  1. 31Reverse Linked List (opens LeetCode in a new tab)Iterative pointer reversalEasycore
    Common mistake
    Overwriting cur.next before saving it.
  2. 32Merge Two Sorted Lists (opens LeetCode in a new tab)Dummy nodeEasycore
    Common mistake
    Forgetting to advance tail.
  3. 33Linked List Cycle (opens LeetCode in a new tab)Fast and slow pointersEasycore
    Common mistake
    Missing the null checks on fast.next.
  4. 34Remove Nth Node From End of List (opens LeetCode in a new tab)Two pointers with a gapMediumcore
    Common mistake
    Removing the head node. The dummy node solves it.
  5. 35Reorder List (opens LeetCode in a new tab)Middle + reverse + weaveMedium
    Common mistake
    Not cutting the first half (mid.next = null) before weaving.
  6. 36Add Two Numbers (opens LeetCode in a new tab)Digit by digit with carryMediumcore
    Common mistake
    Dropping the final carry node.
  7. 37Copy List with Random Pointer (opens LeetCode in a new tab)Map old nodes to new nodesMediumcore
    Common mistake
    Forgetting that the random pointer can be null.
  8. 38LRU Cache (opens LeetCode in a new tab)Hash map + doubly linked listMediumcore
    Common mistake
    Forgetting to delete the evicted key from the map.
  9. 39Reverse Nodes in k-Group (opens LeetCode in a new tab)Group reversalHardcore
    Common mistake
    Reconnecting pointers between groups. Draw it first.