Arrays & Strings / Two Pointers

Use for reverse/subarray ops, palindrome/anagram checks, partitioning, dedupe, pair/sum problems.

What this pattern is

Maintain two indices that move toward each other (or at different speeds) to solve linear-time problems on arrays/strings without extra space. Great for in-place edits, partitioning, and pair-finding.

Exercise: isPalindrome

Task: Determine if a string is a palindrome considering only alphanumeric characters and ignoring case.
Example: "A man, a plan, a canal: Panama" → true; "race a car" → false
Edge cases: punctuation-only strings, unicode letters/digits.

Your Solution

Exercise: reverseChars

Task: Given an array of single-character strings s, reverse it in-place.
Example: ["h","e","l","l","o"] → ["o","l","l","e","h"]
Edge cases: empty array, single char.

Your Solution

Exercise: twoSumSorted

Task: Given a sorted array nums and a target t, return indices [i, j] with nums[i] + nums[j] = t (or [-1,-1] if none). Use two pointers from ends.
Example: nums=[1,2,3,4,6], t=6 → [1,3] (2+4).
Edge cases: duplicates, negative numbers, no solution.

Your Solution