- LeetCode 22 – Generate Parentheses
The problem that teaches constrained backtracking. The lazy solution builds all 4^n bracket strings and filters; the intended one never builds an invalid string, because two small rules make it impossible. Why close < open is sufficient — not just true — the undo step everyone forgets, and why the output being Catalan-sized bounds any possible solution.
- Consistency, Availability and CAP
CAP without the folklore — what the theorem says, what it does not say, and why PACELC is the more useful version day to day. Strong against eventual consistency, read-your-writes and monotonic reads, quorums, and the dual-write problem that appears the moment a second datastore enters the design. Shown against a live Postgres-to-Elasticsearch sink, including exactly where it goes wrong.
- LeetCode 21 – Merge Two Sorted Lists
The merge step of merge sort, isolated. Worth writing carefully rather than quickly, because Merge k Sorted Lists calls it and so does sorting a linked list. The part people over-engineer: splice the remaining list on in a single assignment instead of looping it out. Why the space is O(1), and why <= rather than < is the detail that shows you were thinking.
- LeetCode 20 – Valid Parentheses
The canonical 'you should have reached for a stack' problem. Nesting means the thing you must close next is the thing you opened most recently. The trick that shortens the code: push the closer you expect, not the opener, so the check becomes one equality test. Three failure modes, three checks — and why ArrayDeque beats the legacy Stack.
- LeetCode 19 – Remove Nth Node From End of List
You cannot walk a singly linked list backwards, so the nth node from the end has to be found from the front. Two pointers held a fixed distance apart do it in one pass — but the gap is n + 1, not n, because unlinking a node needs the node before it. Why the dummy head is not optional here, and an honest note on what 'one pass' actually buys.