Data Structures & Algorithms
In 2025 I worked through a series of classic coding-interview problems and wrote up each one: brute force first, then the optimal solution, with Python code and complexity analysis. Many end with where the same idea shows up in real systems, such as the LRU cache behind LLM KV-cache blocks, or the small dynamic program that grows into CTC speech decoding.
Useful if you are preparing for interviews, or just like seeing old algorithms turn up in new places.
Start here
- LRU Cache: the O(1) hash map plus linked list design, with thread safety, TTLs, and the same eviction idea in prediction caches and LLM KV-cache blocks.
- LFU Cache (Least Frequently Used): O(1) LFU with frequency buckets, and how production caches such as W-TinyLFU and Redis approximate it.
- Word Search II: trie-guided search that drops dead prefixes early, the idea behind typeahead and lexicon-constrained speech decoding.
- Word Break: segmentation DP and tries, extended to the most-likely segmentation (Viterbi) that unigram tokenizers use.
- Decode Ways: one small DP that grows into the forward, Viterbi and beam-search algorithms behind CTC speech recognition.
- Merge Intervals: sort-then-sweep done right, applied to cleaning up voice-activity and diarization segments.
- Sliding Window Maximum: the monotonic deque behind rolling peak-latency and audio-level monitoring in O(n).
- Merge K Sorted Lists: the k-way heap merge behind external sorting and sorted-shard data pipelines, with a measured reminder that big-O is not the whole story in Python.
- Longest Increasing Subsequence (LIS): from O(n^2) DP to patience sorting in O(n log n), and the same chaining trick in patience diff, genome alignment and long-transcript alignment.
- Course Schedule (Topological Sort): cycle detection and Kahn’s algorithm, the model behind build systems and ML pipeline orchestrators, plus critical-path scheduling.
Archive
- Two Sum
- Valid Parentheses
- Merge Two Sorted Lists
- Best Time to Buy and Sell Stock
- Maximum Subarray (Kadane’s Algorithm)
- Climbing Stairs
- Binary Tree Traversal
- Validate Binary Search Tree
- Binary Search
- Reverse Linked List
- Add Two Numbers
- Container With Most Water
- Generate Parentheses
- Group Anagrams
- Rotate Image
- Spiral Matrix
- Jump Game
- Unique Paths
- Minimum Path Sum
- Binary Tree Level Order Traversal
- Construct Binary Tree from Preorder and Inorder Traversal
- Kth Smallest Element in a BST
- Lowest Common Ancestor of a Binary Tree
- Number of Islands
- Word Ladder (BFS)
- Clone Graph (DFS/BFS)
- Evaluate Division (Graph/Union-Find)
- Surrounded Regions (DFS/BFS)
- Partition Equal Subset Sum
- Coin Change (Unbounded Knapsack)
- Jump Game II
- Largest Rectangle in Histogram
- Binary Tree Maximum Path Sum
- Serialize and Deserialize Binary Tree
- Alien Dictionary
- Median of Two Sorted Arrays
- Trapping Rain Water
- First Missing Positive
- Wildcard Matching
- N-Queens
- Minimum Window Substring
- Regular Expression Matching
- Sudoku Solver
Recently added
- LFU Cache (Least Frequently Used)
- Sudoku Solver
- Regular Expression Matching
- Minimum Window Substring
- N-Queens
Some posts are drafted with AI assistance and edited by Arun. If you spot an error, let me know and it gets fixed.