System Design DSA — Complete Guide (LRU, LFU, Caches, Data Structures)
Master system design problems that test data structure knowledge: LRU/LFU caches, Twitter feed, file systems, and 15+ design problems with full implementations.
webcoderspeed.com
21 articles
Master system design problems that test data structure knowledge: LRU/LFU caches, Twitter feed, file systems, and 15+ design problems with full implementations.
Implement an LRU (Least Recently Used) cache with O(1) get and put using a doubly linked list and hashmap. Full 5-language solutions.
Implement an LFU cache with O(1) get and put. Uses two hashmaps and per-frequency doubly linked lists to track access frequency and recency simultaneously.
Design a simplified Twitter where users post tweets and follow each other, with getNewsFeed returning the 10 most recent tweets from followed users using a min-heap merge.
Implement a file system that creates paths and associates values with them. Uses a Trie or HashMap to map full paths to values with O(L) operations.
Design a hit counter that counts hits in the last 5 minutes using a deque-based sliding window or circular buffer with O(1) amortised operations.
Design a key-value store that returns values at or before a given timestamp. Uses a hashmap of sorted (timestamp, value) lists with binary search for O(log n) get.
Design a search autocomplete system that returns top 3 historical queries matching the current prefix, sorted by frequency then lexicographically. Uses a Trie with per-node frequency maps.
Design a browser with visit, back, and forward navigation. Uses two stacks (or a doubly-ended array with pointer) for O(1) visit and O(steps) navigation.
Design a leaderboard that tracks player scores, supports score additions, top K sum queries, and player resets using a hashmap with sorted aggregation.
Simulate a snake game on a grid where the snake eats food to grow and dies if it hits walls or itself. Uses a deque for O(1) head/tail and a set for O(1) body collision checks.
Implement a skip list from scratch supporting search, add, and erase in O(log n) expected time. Uses layered linked lists with probabilistic level assignment.
Design a log storage system that retrieves log IDs within a timestamp range at a specified granularity (Year, Month, Day, Hour, Minute, Second).
Design a phone directory managing available and allocated numbers with O(1) get, check, and release using a queue of free numbers and a boolean availability array.
Design an in-memory key-value database that supports set, get, delete, and rank operations. Demonstrates combining hashmaps with sorted structures for efficient multi-key queries.
Implement a stack that supports push, pop, top, and retrieving the minimum element in O(1) time using an auxiliary min-stack that tracks minimums at each level.
Maintain a running median from a data stream using two heaps: a max-heap for the lower half and a min-heap for the upper half, rebalancing after each insertion.
Implement a circular queue (ring buffer) with fixed capacity supporting enQueue, deQueue, Front, Rear, isEmpty, and isFull in O(1) time using head and tail pointers.
Design a URL shortener like TinyURL that encodes long URLs to short codes and decodes them back. Uses base-62 encoding with a counter or random string generation.
Design a parking system with big, medium, and small spaces. O(1) addCar checks if space is available and decrements the counter, returning whether the car was parked.
Complete recap of all 20 system design DSA problems: pattern classification, time complexities, key data structures, and decision framework for choosing the right design approach.