Two Pointers
Two indices moving with a rule — pairs in sorted arrays, in-place filtering, merging, and 3Sum.
This topic is part of Pro.
Free covers the C and Python courses, the first three DSA topics, the opening system design lessons and the beginner AI lessons, all with the full coach. Pro opens the rest of the library in the FollowtheDamnCode app.
What is in it
- 1Pointers from both endsStart at the two ends of a sorted array and let the comparison decide which side moves. Pro
- 2Reader and writer pointersA fast pointer reads every item, a slow one marks where the next kept item goes — filtering in place. Pro
- 33Sum and k-sumSort, fix one number, and run two pointers on the rest — skipping duplicates as you go. Pro
- 4One pointer per sequenceMerge two sorted arrays, check subsequences, and intersect lists by walking both at once. Pro
- 5Trapping Rain WaterWater above each bar depends on the tallest walls to its left and right — two pointers find both in one pass. Pro