WRITING
Notes on building and running systems
Engineering write-ups — architecture, security, and the occasional war story.
#array · All writing
Series
Tags
- #leetcode 50
- #array 13
- #dfs 11
- #bfs 9
- #dynamic-programming 9
- #recursion 9
- #trees 7
- #arrays 6
- #binary-search 6
- #hash-table 6
- #string 6
- #two-pointers 6
- #backtracking 4
- #dp 4
- #graphs 4
- #greedy 4
- #matrix 4
- #sliding-window 4
- #hash-map 3
- #heap-priority-queue 3
- #linked-list 3
- #stack 3
- #binary-search-tree 2
- #heap 2
- #math 2
- #memoization 2
- #priority-queue 2
- #sorting 2
- #strings 2
- #binary-tree 1
- #bit-manipulation 1
- #bucket-sort 1
- #counting 1
- #cycle-detection 1
- #divide-and-conquer 1
- #geometry 1
- #kadane 1
- #multi-source-bfs 1
- #prefix-sum 1
- #quickselect 1
- #simulation 1
- #string-matching 1
- #topological-sort 1
- #union-find 1
01
Permutations: building every ordering with backtracking
LeetCode 46 is the cleanest introduction to decision-tree backtracking — three approaches from a one-liner to a swap-in-place variant, each revealing something different about how to think through enumeration problems.Jun 14, 2026 · 10 min read · #00043
02
Kth Largest Element: three ways to avoid sorting the whole array
Finding the kth largest element looks trivial until you hit a case where sorting is too slow or you need to hold a streaming answer. The min heap and QuickSelect approaches each solve a different version of that problem — and understanding when to reach for each one matters more than memorizing either.Jun 14, 2026 · 12 min read · #00037
03
Tracking Min and Max Together: Why the Product Subarray Problem Breaks Kadane's
LeetCode 152 looks identical to Maximum Subarray until a negative number shows up and flips everything. Walk through brute force and the two-lookback DP that handles sign flips — with a full trace, edge-case analysis, and the mental model you carry to future problems.Jun 14, 2026 · 8 min read · #00052
04
Combination Sum: backtracking with unlimited reuse
LeetCode 39 looks like a straightforward backtracking problem, but the devil is in one detail: you can reuse the same number. That single rule changes how you control the search and where you prune.Jun 14, 2026 · 10 min read · #00042
05
Subsets: three ways to build a power set
LeetCode 78 has three genuinely different solutions — bit manipulation, backtracking, and iterative expansion — and understanding all three reveals why 'generate all subsets' is the canonical first backtracking problem.Jun 14, 2026 · 10 min read · #00041
06
Container With Most Water: why you always move the shorter line
The greedy argument is what makes the two-pointer correct here — not just fast. Moving the taller line can only make things worse; moving the shorter one is the only way to possibly improve. That reasoning is the whole solution.Jun 13, 2026 · 12 min read · #00015
07
Trapping Rain Water: from O(n) space to O(1) with two pointers
The brute force is obvious. The prefix/suffix array approach is clean. The two-pointer solution is where it gets interesting — you can eliminate the auxiliary arrays entirely by recognising that you only need the running max from whichever side is shorter.Jun 13, 2026 · 15 min read · #00016
08
Binary Search: the off-by-one minefield
Binary search is one of those algorithms everyone thinks they understand until they have to implement it from scratch. The logic is four lines. The tricky part is the boundary conditions — whether to use lo <= hi or lo < hi, and whether mid goes left or right on a miss.Jun 13, 2026 · 13 min read · #00023
09
Two Sum II: why sorted order makes two pointers work
The sorted input is not a coincidence — it's the contract the two-pointer approach depends on. Once you know the array is sorted, you can place pointers at both ends and move them with purpose: too large, shrink the right; too small, grow the left.Jun 13, 2026 · 10 min read · #00013
10
Find Minimum in Rotated Sorted Array: which half is sorted?
The array is sorted, then rotated — which breaks the simple binary search invariant. The fix: compare mid to the right boundary. If mid is less than right, the minimum is in the left half (including mid); otherwise it's in the right half (excluding mid).Jun 13, 2026 · 12 min read · #00025
11
Best Time to Buy and Sell Stock: tracking the running minimum
You want to buy low and sell high, but you can only sell after you buy. The O(n) solution tracks the lowest price seen so far and computes profit at each step — it's a single pass that the sliding-window framing makes obvious.Jun 13, 2026 · 10 min read · #00017
12
3Sum: two pointers inside a sorted loop
3Sum takes Two Sum II one level up: fix one element, then run Two Sum II on the rest. Sorting first lets you skip duplicates cleanly, which is the tricky part most implementations get wrong.Jun 13, 2026 · 12 min read · #00014
13
Search in Rotated Sorted Array: two sorted halves, one extra condition
After rotation, at least one of the two halves around mid is always sorted. That's the invariant that keeps binary search working. You just need one extra check to know which half is sorted, and then whether your target is in it.Jun 13, 2026 · 11 min read · #00026
Occasional notes on what I'm building
Get an email when I publish a new post — engineering write-ups, no spam. Unsubscribe anytime.