Two-pointers

87 articles

dsa17 min read

Move Zeroes — The Write Pointer Pattern Every Interview Tests [Microsoft, Amazon]

LeetCode 283 is the gateway to the two-pointer partition pattern used across dozens of harder problems. Learn why it appears in almost every Microsoft and Amazon phone screen, master the write-pointer mental model with a step-by-step dry run, and understand when to swap vs. overwrite — with Python and JavaScript solutions fully annotated.

Read →
dsa12 min read

Merge Sorted Array — Why Merging From the Back Is the Elegant O(1) Solution

Most candidates try to merge nums1 and nums2 from the front and run into a subtle overwrite bug. Learn why starting from the back is the key insight, how three pointers keep the logic clean, and how this same trick powers the merge step in Merge Sort. Full Python and JavaScript solutions included.

Read →
dsa13 min read

Valid Palindrome — Two Pointer Skip Non-Alphanumeric [Meta Easy]

Master LeetCode 125 — Valid Palindrome with the O(1)-space two-pointer technique. Learn why every FAANG loop starts here, visualize the pointer walk on a classic example, avoid the four most common pitfalls, and unlock the palindrome follow-up chain: LC 680, LC 5, and LC 647.

Read →
dsa15 min read

Container With Most Water — Greedy Two-Pointer Proof [Google, Amazon, Meta]

LeetCode 11 explained from scratch: why this is a greedy problem, the formal proof that you must always move the shorter pointer, a full step-by-step dry run, common traps, and clean Python + JavaScript solutions. Master the pointer-elimination pattern that appears throughout FAANG interviews.

Read →
dsa14 min read

Sort Colors [Medium] — Dutch National Flag Algorithm Explained

Master Dijkstra's Dutch National Flag algorithm to sort 0s, 1s, and 2s in a single pass with O(1) space. Understand the three-pointer invariants, the critical bug most candidates make, and how this pattern unlocks a family of partition problems.

Read →
dsa16 min read

Minimum Window Substring [Hard] — The Canonical Sliding Window Problem

Master LeetCode 76 — the gold-standard Hard sliding window problem asked at Google, Meta, and Amazon. Learn the "formed" counter trick that reduces window validity checks from O(|t|) to O(1), trace through a full dry run, and avoid the five bugs that trip up 90% of candidates.

Read →