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

Recently added


Some posts are drafted with AI assistance and edited by Arun. If you spot an error, and it gets fixed.