WRITING
Notes on building and running systems
Engineering write-ups — architecture, security, and the occasional war story.
#design · All writing
Series
Tags
- #leetcode 50
- #dfs 18
- #recursion 17
- #bfs 11
- #trees 11
- #backtracking 9
- #array 7
- #dynamic-programming 7
- #graphs 7
- #hash-map 7
- #linked-list 7
- #design 5
- #greedy 5
- #heap-priority-queue 5
- #matrix 5
- #string 5
- #two-pointers 5
- #binary-tree 4
- #cycle-detection 4
- #dp 4
- #sorting 4
- #stack 4
- #binary-search 3
- #divide-and-conquer 3
- #hash-table 3
- #priority-queue 3
- #binary-search-tree 2
- #data-structures 2
- #hard 2
- #heap 2
- #math 2
- #memoization 2
- #monotonic-stack 2
- #simulation 2
- #topological-sort 2
- #arrays-hashing 1
- #combinatorics 1
- #constraint-satisfaction 1
- #constraint-validation 1
- #counting 1
- #data-stream 1
- #depth-first-search 1
- #feasibility 1
- #flood-fill 1
- #geometry 1
- #hash-set 1
- #in-place 1
- #kadane 1
- #level-order 1
- #monotonic 1
- #optimization 1
- #palindrome 1
- #post-order 1
- #quickselect 1
- #sliding-window 1
- #string-matching 1
- #strings 1
- #two-pass 1
- #two-stacks 1
- #union-find 1
01
Design Twitter: merge k sorted timelines with a heap
LeetCode 355 looks like a systems design question but it's really a data-structure composition problem. The brute-force scan works for tiny inputs; the heap-based approach shows how the 'merge k sorted lists' pattern produces a news feed in O(F log F) time regardless of total tweet volume. Both approaches fully traced, with edge cases and the trade-off reasoning you'd need in an interview.Jun 14, 2026 · 13 min read · #00081
02
Kth Largest in a Stream: why a size-k min-heap is the right boundary
Tracking the kth largest element across an unbounded stream seems to require storing everything. A size-k min-heap proves you need to keep only k elements, and makes each add call O(log k) instead of O(n log n). This article walks both approaches — sort-on-every-add brute force and the heap solution — with a by-hand trace, edge-case reasoning, and the design insight about why the heap root is exactly the answer.Jun 14, 2026 · 12 min read · #00080
03
LRU Cache: why O(1) eviction requires you to hold two data structures at once
LeetCode 146 forces you to think about what O(1) eviction actually demands. A naive array approach fails on both get and put. The production solution — a hash map pointing into a doubly linked list with sentinel nodes — is a textbook example of combining two structures so each covers the other's weakness. This article walks through both approaches, traces the state machine step by step, and explains why the sentinel pattern is not optional.Jun 14, 2026 · 13 min read · #00069
04
Min Stack: tracking the minimum without scanning it
Every getMin() call needs to return the current minimum in O(1). The trick is not to compute it on demand — it is to preserve it across push and pop operations using auxiliary state that moves with the stack. There are two clean ways to store that state, and they differ only in where you put it.Jun 14, 2026 · 12 min read · #00056
05
Serialize and Deserialize Binary Tree: encoding structure, not just values
Turning a binary tree into a string and back is a design problem disguised as a coding exercise. The core insight is that you need enough structural information in the encoding to reconstruct the tree unambiguously. BFS level-order and DFS preorder each solve this differently, with real trade-offs in string length, stack behavior, and how naturally the decode mirrors the encode.Jun 14, 2026 · 12 min read · #00079
Occasional notes on what I'm building
Get an email when I publish a new post — engineering write-ups, no spam. Unsubscribe anytime.