intro practice · coding problem

Valid palindrome with two pointers

Given a string, decide if it reads the same forwards and backwards, ignoring case and non-alphanumeric characters. Use two pointers, no extra string.

The mechanism

Two pointers replace a nested loop with a single pass by exploiting structure — usually a sorted array or a sequence with a monotonic property. The pointers move toward or away from each other based on a comparison, so each element is visited once.

Study Two Pointers

Expected evidence

isPalindrome('A man, a plan, a canal: Panama') -> true

Try this drill in the practice workspace →

Hints when you need them
  • Start one pointer at each end, move inward.
  • Skip non-alphanumeric characters without allocating a cleaned copy.

Watch for these mistakes

  • Using two pointers on unsorted data when the technique needs order
  • Off-by-one errors at the start/end conditions
  • Moving the wrong pointer and skipping valid pairs

Check the sources

Practice the same mechanism

Browse all practice briefs