WRITING
Notes on building and running systems
Engineering write-ups — architecture, security, and the occasional war story.
#monotonic-stack · 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
Largest Rectangle in Histogram: the monotonic stack as a boundary oracle
Every bar in the histogram can be the height of a maximal rectangle — the question is how wide that rectangle can stretch. A monotonic stack answers that in O(n) by telling you exactly when each bar's reign as the minimum height is over. Here is how brute force makes the problem clear, and why the stack makes it fast.Jun 14, 2026 · 12 min read · #00060
02
Car Fleet: how arrival time collapses a simulation into a stack sweep
Car Fleet (LeetCode 853) looks like a simulation problem. It is not. Once you realise that two cars merge into one fleet exactly when the trailing car's arrival time is no greater than the leading car's, the whole thing reduces to a monotone stack sweep over sorted arrival times. This article works through both the brute-force simulation and the optimal sort-plus-stack approach, with a full by-hand trace, edge-case analysis, and a first-person take on what to actually write in an interview.Jun 14, 2026 · 14 min read · #00059
Occasional notes on what I'm building
Get an email when I publish a new post — engineering write-ups, no spam. Unsubscribe anytime.