Module 7 · 3 lessons · about 4 hours 20 minutes
Linked lists
Nodes and pointers, reversing and merging lists, fast and slow pointers, and designing an LRU cache from a dictionary and a linked list.
- Lessons
- 0/3
- Exercises
- 0/22
- Code
- 0/3
- Problems
- 0/12
- Checkpoint
- Not taken
Already comfortable with this? Take the checkpoint cold. If you pass, move on and come back only for what you missed.
- 1Nodes and pointersA linked list is a chain of nodes, each holding a value and a pointer to the next one. Walk it by following the pointers from node to node, reverse it by turning every pointer around, and build new lists, such as two sorted lists merged into one, behind a placeholder node.1 h 30 min
- 2Fast and slow pointersTwo pointers can walk one linked list at different speeds, or at the same speed with a fixed gap between them. That finds the middle in one walk, catches a list that loops forever, and finds the n-th node from the end, all with O(1) extra space.1 h 35 min
- 3Designing an LRU cacheA cache with a size limit has to choose what to forget. An LRU cache forgets the key used longest ago, and a dict plus a doubly linked list makes every get and put O(1) on average.1 h 15 min
- Checkpoint12 questions. Pass with 80% to finish the module.
Problems for this module
The lessons teach some of these step by step (each says which). The rest are practice: try each in its target time, and solved problems come back for spaced re-solves.
- easyReverse a linked list15 min
- easyMerge two sorted lists15 min
- mediumAdd two numbers25 min
- easyRemove nodes with a given value15 min
- easyMiddle of a linked list15 min
- easyLinked list cycle15 min
- mediumRemove the n-th node from the end25 min
- mediumReorder a list from both ends25 min
- easyPalindrome linked list15 min
- mediumLRU cache25 min
- mediumHit counter25 min
- hardLFU cache40 min