01
Two Pointers
Sorted arrays and pair/triplet search.
6 pages
- Pattern 01: Two Pointers (Opposite Ends)Pattern guide
Memorise one skeleton. Every opposite-ends problem is this loop with the if/else body swapped.
- LC 125Valid Palindrome (LC 125)Easy
Compare characters from both ends while skipping non-alphanumeric characters and ignoring case.
- LC 283Move Zeroes (LC 283)Easy
Maintain a “write” position for the next non-zero while scanning with a “read” pointer (or compact with a single slow/fast index).
- LC 344Reverse String (LC 344)Easy
Swap characters symmetrically from both ends until pointers meet; char[] is mutable, so this is true O(1) extra space.
- LC 977Squares of a Sorted Array (LC 977)Easy
In a sorted array, the largest squares come from the ends (most negative or most positive); merge into a result array from right to left.
- Valid Palindrome — runnable JavaJava
Runnable Java file — no imports, no Maven needed. Save it and run java ValidPalindrome.java.