17. Linked List
Reverse, fast & slow pointers, merge, and LRU cache.
Understand the topic
A linked list is a chain of nodes, where each node knows only the next one (and in a doubly linked list, the previous one too). You can't jump to index i; you walk. In exchange, inserting or removing next to a node you already hold is O(1).
Four tools solve almost everything here. A dummy head node removes edge cases at the front. Reversing with prev, cur and next handles flips. Fast and slow pointers find the middle and detect cycles. A HashMap plus a doubly linked list gives O(1) caches. Draw the arrows on paper before you code.
| # | Problem | Pattern | Level | ||
|---|---|---|---|---|---|
| 1 | Reverse Linked List #206 | Iterative pointer reversal | Easy | LeetCode β | |
| 2 | Middle of the Linked List #876 | Fast & slow pointers | Easy | LeetCode β | |
| 3 | Linked List Cycle #141 | Floyd's cycle detection | Easy | LeetCode β | |
| 4 | Merge Two Sorted Lists #21 | Dummy head merge | Easy | LeetCode β | |
| 5 | Intersection of Two Linked Lists #160 | Two pointers switching lists | Easy | LeetCode β | |
| 6 | Palindrome Linked List #234 | Middle + reverse second half | Easy | LeetCode β | |
| 7 | Remove Duplicates from Sorted List #83 | In-place unlink | Easy | LeetCode β | |
| 8 | Remove Nth Node From End of List #19 | Gap of n between two pointers | Medium | LeetCode β | |
| 9 | Linked List Cycle II #142 | Floyd's cycle entrance | Medium | LeetCode β | |
| 10 | Add Two Numbers #2 | Digit-by-digit with carry | Medium | LeetCode β | |
| 11 | Odd Even Linked List #328 | Two chains, then join | Medium | LeetCode β | |
| 12 | Reorder List #143 | Middle + reverse + weave | Medium | LeetCode β | |
| 13 | Reverse Linked List II #92 | Reverse a sublist in place | Medium | LeetCode β | |
| 14 | Copy List with Random Pointer #138 | Interleave copies | Medium | LeetCode β | |
| 15 | LRU Cache #146 | HashMap + doubly linked list | Medium | LeetCode β | |
| 16 | Flatten a Multilevel Doubly Linked List #430 | Doubly linked list splicing | Medium | LeetCode β | |
| 17 | Merge k Sorted Lists #23 | Min-heap of list heads | Hard | LeetCode β | |
| 18 | Reverse Nodes in k-Group #25 | Group reversal with reconnection | Hard | LeetCode β | |
| 19 | LFU Cache #460 | Frequency buckets of LinkedHashSets | Hard | LeetCode β |
Nothing matches that filter.
Work top to bottom β each list goes from easy to hard. Try a problem for at least 15 minutes before opening a hint. Ticks are saved in your browser.