WRITING
Notes on building and running systems
Engineering write-ups — architecture, security, and the occasional war story.
#two-pointers · 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
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
02
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
03
Reorder List: three operations you already know
Reorder List looks custom, but it decomposes cleanly into three operations you've seen before: find the midpoint (slow/fast pointers), reverse the second half, then merge alternating nodes. Each sub-problem is its own solved problem. The insight is the decomposition.Jun 13, 2026 · 14 min read · #00029
04
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
05
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
06
Valid Palindrome: the two-pointer read from both ends
A string is a palindrome if it reads the same forwards and backwards after stripping non-alphanumeric characters. Two pointers placed at the ends and walked inward check this in O(n) time and O(1) space — no reversed copy needed.Jun 13, 2026 · 9 min read · #00012
Occasional notes on what I'm building
Get an email when I publish a new post — engineering write-ups, no spam. Unsubscribe anytime.