SERIES
Graphs
Treat grids and adjacency lists as the same object.
In this seriesNEWSLETTER
01
Number of Islands: flood-fill, BFS, and when Union-Find actually earns its keep
LeetCode 200 asks you to count disconnected land masses in a binary grid. Three approaches — DFS flood-fill, BFS, and Union-Find — all get there, and the constraints tell you exactly which one to reach for and why.Jun 14, 2026 · 13 min read · #00045
02
Clone Graph: deep-copying a cyclic structure without infinite loops
Cloning a graph means producing a fully independent copy of every node and every edge — but the graph has cycles, which means a naive recursive walk will loop forever. The fix is one hash map and a rule about when to register a clone.Jun 14, 2026 · 9 min read · #00046
03
Course Schedule: cycle detection is the whole problem
LeetCode 207 looks like a scheduling question but it is really asking whether a directed graph contains a cycle. Once you see that, two clean solutions fall out — a three-color DFS and Kahn's BFS topological sort. Both run in O(V+E); the choice between them turns on whether you need the sorted order later.Jun 14, 2026 · 11 min read · #00047
04
Rotting Oranges: why multi-source BFS beats simulating minute by minute
LeetCode 994 asks how long contagion takes to spread across a grid. The naive simulation works, but a single-pass multi-source BFS is both cleaner and a full order of magnitude faster — and the constraints show exactly why.Jun 14, 2026 · 11 min read · #00048
Occasional notes on what I'm building
Get an email when I publish a new post — engineering write-ups, no spam. Unsubscribe anytime.