This site uses one functional cookie to keep feature rollouts consistent for you. Nothing is set until you choose. See the privacy notice.
Dev notes
The Learn pages are interactive walkthroughs of the things I keep having to explain properly — binary search, sliding window, two pointers, hash maps, recursion and backtracking, dynamic programming, trees and graphs, stacks and queues, memoization, debounce and throttle, event delegation, async patterns, and the newest one on AI agent patterns. The interesting engineering isn't any single demo. It's that thirteen of them each grew their own copy of the same stepper, and what went wrong when I finally pulled that apart.
Every demo needs the same thing: a list of steps, a current index, play and pause, forward and back, reset, and keyboard control. I built that inline the first time because one page doesn't need an abstraction. By the time there were a dozen, the shape had been retyped a dozen times, and each copy had drifted — different key handling, different behaviour at the end of the list, different ideas about what pause meant when you were already at the last step.
That is the version of duplication I actually care about. Not the typing, which is cheap, but the fact that thirteen copies means thirteen slightly different answers to the same question, and no one place to fix any of them. It became one useStepPlayer hook.
Before consolidating I wrote tests for the stepper behaviour, which is the order I'd insist on for anything that already ships: characterise what it does, then change how it does it. Those tests immediately caught an overrun — the player could step one past the end of the list.
The fix is the part worth keeping. The autoplay timer was deciding whether to stop inside the state updater, checking the index it was about to set. That reads fine and is wrong: an updater has to be a pure function of previous state, and using it to decide whether to cancel a timer is a side effect hiding in a place React is allowed to call twice. The stepper now stops from the callback, where the decision belongs, and the updater only computes the next index.
Learn is thirteen near-identical routes, which makes it the cheapest place in the app to prove a cross-cutting change and the most expensive place to get one wrong. Several passes landed here first:
AmbientBackground primitive and then PageShell, which collapsed the per-page background boilerplate onto one component.motion to m migration, which only pays off when every route does it, since one straggler pulls the full bundle back in.buildArticleMetadata so the head tags come from one helper rather than being hand-rolled per page.Update — August 10, 2026
This page existed for months with no write-up, which I only noticed when I audited which features had one. Two others were in the same state, and the work-portfolio write-up turned out to exist while nothing linked to it.
Writing it up surfaced the thing I would actually tell someone: the hook extraction was not the valuable part. Writing the characterisation tests first was. They found a real off-by-one that had been shipping, and they are the reason I could change thirteen pages at once and believe the result.
Update — November 4, 2026
Thirteen demos showed me how sliding window or backtracking works once I already knew to use it. None of them helped with the step a LeetCode interview actually tests, which is reading a problem cold and knowing what to reach for. So I built/learn/interview-prep: 23 patterns, the wording that gives each one away, a template, the traps, and a ladder of LeetCode problems to practise on, all in TypeScript.
Every pattern carries its signals as phrases ("longest substring", "k closest", "minimum number of operations"), with the strongest flagged, plus a short list of when it's probably something else. That one field drives the pattern page, the drill and a signal finder on the hub: paste a problem statement and it ranks patterns by which phrases matched and highlights them in the text.
rankPatternsForText("Given a string s, find the length of the longest
substring without repeating characters.")
[{ patternId: "sliding-window", score: 5,
matchedPhrases: ["longest substring", "substring",
"without repeating characters"] }]Phrase matching counts words, not what they mean together. A sorted array plus a target sum is the classic two-pointer problem, but the hash-map phrases outnumber the one that says sorted:
"Given a sorted array of integers and a target, return the indices of the two numbers that add up to target." arrays-hashing 3 ["indices of the two numbers", "add up to target"] two-pointers 2 ["sorted array"] binary-search 1 ["sorted"]
I could weight "sorted" up until this passes, but that tunes the finder to the example I happened to try. Showing the matched phrases next to each guess is the better fix. Two plausible answers and the reason for each is the conversation I want to have with myself in an interview anyway, and a confident single answer would hide it.
The research I leaned on for the study plan is the testing effect (Roediger and Karpicke, 2006), spacing (Cepeda and colleagues, 2006) and interleaving (Rohrer and Taylor, 2007). Reading a solution feels like learning and mostly isn't. So each template sits behind "Show the template", ratings put problems back on a 1, 3, 7, 14, 30, 60 day ladder, and the drill mixes every pattern together by default, because practising one topic in a block never makes me choose.
The roadmap test looks up each pattern's link by a regex anchored on its name. "Binary Search" and "Binary Search Trees" both start the same way:
TestingLibraryElementError: Found multiple elements with the role "link" and name `/^Binary Search/`
My first instinct was to loosen the test. But a reader scanning the roadmap has the same problem as the regex, so the tree pattern became "BSTs" instead.
Ratings started in localStorage, which is fine until I practise on my phone and review on my laptop. They now live in portfolio_api per user behind a /api/practice proxy, and the first sign-in moves whatever a browser kept onto the account and clears the local copy. The signed-in save test failed on the first run:
× saves a rating to the account and leaves localStorage alone AssertionError: expected [] to have a length of 1 but got +0
The buttons were live before /api/mehad answered, so the click went to localStorage and no request was ever made. In practice the next load would have imported it, which is why it looked harmless. But "it gets fixed on the next visit" isn't what I want from a store. Rating now waits until the session is known and, when signed in, until the account has loaded. A failed read or save says so on the page instead of showing an empty schedule.
The E2E job ran all 132 tests green, then failed on the size check that runs after them:
/learn/interview-prep budget 360.0KB (catch-all ceiling) actual 363.1KB over by 3.1KB
I assumed the pattern data was the weight, since all 23 patterns ship to the client. Splitting the route's chunks said otherwise: one of them was nothing but zod, about 62KB gzipped, pulled in to check the shape of what's in localStorage. My first fix waszod/mini, which is meant to tree-shake down to almost nothing. It saved 5KB, and a namespace import saved nothing more, because Turbopack doesn't shake it here. The check is four fields, so it became a small type guard, with a test written first to pin that unreadable progress still throws. All three routes came down by about 57KB, to roughly 300KB.
Found 2 dead export(s) — nothing imports these: src/lib/leetcode/patterns/index.ts:61 - patternById src/lib/leetcode/patterns/index.ts:70 - leetCodeUrl
Both are imported from half a dozen files. ts-prune doesn't follow an import of a directory'sindex.ts, which is why the only other one in the repo is on its ignore list. They got an ignore comment with that reason rather than a rename to dodge the tool.
A ladder of links is only half useful when I get stuck at 11pm. So all 223 problems now have a TypeScript solution, and each row reveals it in three levels: Hide, Basic logic, Full solution. The middle level is the useful one. It gives the approach as three short steps with the time and space and no code, so I can still write the solution myself and only peek at the code to check it. Jumping straight to the code is the reading-isn't-learning trap the template already guards against.
Every solution carries its own checks, and the same harness that tests the templates runs them all and type-checks them in strict mode. It caught one that ran fine and still wasn't good TypeScript:
graphs / solution / 01-matrix: Type 'number' is not assignable to type '0 | -1'.
A ternary of two literals infers a literal type, so the distance grid couldn't hold a 2. JavaScript doesn't care. An interviewer watching me write TypeScript might. The solutions live in their own catalogue, not in the pattern data, because the hub and the drill ship that data to the browser and these would roughly double it. The pattern page's server component hands its client just that pattern's ten or so.
One solution per problem hid the alternatives an interviewer asks about next. I didn't want two of everything, so eight problems got a second way, each because it says something the first doesn't: Quickselect next to the heap for Kth Largest, the doubly linked list an LRU cache's Map trick stands in for, merging in pairs for k sorted lists, the O(n²) DP before the patience-sorting one. It sits under the first at the same level, so Basic logic shows both sets of steps and Full solution shows both programs, each with its own checks.
Number of Islands was the one where the second way turned out to matter. The recursive flood fill is the version everyone writes, and on a grid that's all land it recurses once per cell:
numIslands(300 x 300 grid of "1") recursive DFS RangeError: Maximum call stack size exceeded
It already overflowed at 100 by 100. The iterative BFS carries a 300 by 300 case in its checks, so the reason to know it is now in the test suite rather than in my head.
The finder's test checks it against the short prompts I wrote for each problem. Those prompts use my phrasing, which is the phrasing the signals were written from. So I fetched LeetCode's real statements for all 223 problems and scored it on those too:
top 1 top 3 my prompts 189/223 212/223 LeetCode's statements 163/223 196/223 theirs, after pruning 166/223 195/223
Then I counted, for each phrase, how often it fired on its own pattern's problems against everyone else's. Ten fired mostly elsewhere. "Pair" and "reverse" were two-pointer signals that turn up all over the catalogue, and "permutation" sent Permutations, a backtracking problem, to sliding window because Permutation in String uses the word. That one became "a permutation of". Dropping the rest bought three first picks and cost one top-three, which is the honest size of it. I didn't keep tuning against the real statements, since that would only move the overfitting from my prompts to theirs.
A review pass over the whole branch read the drill's deck builder next to the beat above about interleaving. New cards came out pattern by pattern, so a first session was every Arrays and Hashing card before a single Two Pointers one: blocked practice, labelled mixed. The tests checked which cards were due, never their order. The deck now deals one problem from each pattern per round:
const rounds = Math.max(...patterns.map((pattern) => pattern.problems.length));
return Array.from({ length: rounds }, (_, round) =>
patterns.flatMap((pattern) => {
const problem = pattern.problems[round];
return problem ? [{ problem, patternId: pattern.id }] : [];
}),
).flat();The same pass found the pattern page's client component importing the whole catalogue to look up its neighbours and prerequisites. The server now works those out and passes names and ids, and a missing pattern, prerequisite or solution throws at build time instead of rendering a gap:
/learn/interview-prep/[pattern] first-load JS, gzipped before 300.0KB after 242.7KB
The pass took things out as well: drill and finder options nothing passed, two tests that only restated their own data, and copies of the same class strings across seven files. A failed sign-in check used to count as signed out, which would have saved a signed-in rating into the browser. It's an error on the page now, and rating stays off until the session is known.