Design
LeetCode 460: LFU Cache
·3 mins
LeetCode
Hard
Hash-Table
Linked-List
Design
Doubly-Linked-List
LeetCode 460 note: key → node, freq → doubly linked list, plus a min_freq; within the same frequency, LRU decides what to evict
LeetCode 146: LRU Cache
·3 mins
LeetCode
Medium
Hash-Table
Linked-List
Design
Doubly-Linked-List
LeetCode 146 note: a hash map finds nodes and a doubly linked list keeps the usage order; both get and updating an existing key must move the node to the front
LeetCode 449: Serialize and Deserialize BST
·2 mins
LeetCode
Medium
String
Tree
Depth-First-Search
Breadth-First-Search
Design
Binary-Search-Tree
Binary-Tree
LeetCode 449 note: for a BST, pre-order without null markers is enough; deserialize recursively with bounds in O(n)
LeetCode 297: Serialize and Deserialize Binary Tree
·2 mins
LeetCode
Hard
String
Tree
Depth-First-Search
Breadth-First-Search
Design
Binary-Tree
LeetCode 297 note: pre-order with null markers identifies the tree uniquely; deserialize by consuming tokens from an iterator
LeetCode 173: Binary Search Tree Iterator
·2 mins
LeetCode
Medium
Stack
Tree
Design
Binary-Search-Tree
Binary-Tree
Iterator
LeetCode 173 note: flattening to an array is simple but uses O(n) space; the follow-up keeps the left spine on a stack for amortized O(1) and O(h) space
Segment Tree and Fenwick Tree
·3 mins
Algorithm
Segment-Tree
Binary-Indexed-Tree
Design
Point updates with range queries: a Fenwick tree (binary indexed tree) jumps by i & -i, and a segment tree recursively halves the range; both take O(log n) per operation
Queue and Design Problems
·3 mins
Algorithm
Queue
Design
Iterator
Lazy-Deletion
Circular queues, zigzag iterators, FIFO matching with cancellation, and the data structure combinations that design problems keep using
LeetCode 716: Max Stack
·3 mins
LeetCode
Hard
Stack
Heap
Design
Lazy-Deletion
LeetCode 716 note: store unique ids on both the stack and the heap, record deletions by id, and discard deleted entries lazily; tracking values cannot tell duplicates apart
LeetCode 622: Design Circular Queue
·2 mins
LeetCode
Medium
Queue
Design
Array
LeetCode 622 note: a fixed array plus head and count, every position taken modulo the capacity, and count deciding empty versus full
LeetCode 2102: Sequentially Ordinal Rank Tracker
·3 mins
LeetCode
Hard
Heap
Design
Two-Heaps
LeetCode 2102 note: two heaps for “top k” and “the rest”, with a custom lt for reversed string order
LeetCode 307: Range Sum Query - Mutable
·3 mins
LeetCode
Medium
Segment-Tree
Binary-Indexed-Tree
Design
Array
LeetCode 307 note: point updates with range sums make prefix sums O(n) per update; a segment tree or Fenwick tree makes both operations O(log n)
LeetCode 281: Zigzag Iterator
·2 mins
LeetCode
Medium
Queue
Design
Iterator
LeetCode 281 note: a queue of unfinished sources, take one value in turn and put the source back if anything remains; it generalizes to k sources