Twelve problems that drill the two-pointer pattern from Lesson 3. The reps are the point — read the approach, try it yourself first, then check the code. Each solution here was actually run and tested.
How to practise. For each problem: spend 2–3 minutes deciding which two-pointer shape it is (converging ends? fast/slow? one array vs two?), write the loop, then dry-run it on the example. If you get stuck for more than ~20 minutes, read the approach, understand it, close the page, and re-solve from memory the next day.
The 12 problems
- 1Valid Palindrome (LeetCode 125)EasyCheck if a string reads the same both ways, ignoring case and symbols: compare from both ends inward.arrow_forward
- 2Remove Duplicates from Sorted Array (LeetCode 26)EasyCompact a sorted array in place so each value appears once: a write pointer trails a read pointer.arrow_forward
- 3Move Zeroes (LeetCode 283)EasyPush every zero to the end in place, keeping the other numbers in order: swap non-zeros to a write pointer.arrow_forward
- 4Squares of a Sorted Array (LeetCode 977)EasyReturn the sorted squares of a sorted array: the biggest square is always at an end, so fill from the back.arrow_forward
- 5Backspace String Compare (LeetCode 844)EasyCompare two strings typed with '#' as backspace: walk both from the right, skipping erased characters.arrow_forward
- 6Two Sum II – Input Array Is Sorted (LeetCode 167)MediumFind two numbers in a sorted array that add to a target: move the left end up or the right end down.arrow_forward
- 73Sum (LeetCode 15)MediumFind all unique triplets summing to zero: sort, fix one number, two-pointer the rest, skip duplicates.arrow_forward
- 83Sum Closest (LeetCode 16)MediumFind the triplet sum nearest to a target: sort, fix one number, converge two pointers, keep the best gap.arrow_forward
- 94Sum (LeetCode 18)MediumFind all unique quadruplets with a target sum: sort, fix two numbers, two-pointer the rest, skip duplicates.arrow_forward
- 10Container With Most Water (LeetCode 11)MediumPick two walls that hold the most water: start at both ends and always move the shorter wall inward.arrow_forward
- 11Sort Colors (LeetCode 75)MediumSort an array of 0s, 1s and 2s in one pass: three pointers grow a 0-zone, a 1-zone and a 2-zone.arrow_forward
- 12Trapping Rain Water (LeetCode 42)HardTotal the rain trapped between bars: water over a bar is set by the smaller of the tallest bars on each side.arrow_forward