Illustration showing how a string is checked to determine if it is a palindrome

How to check if a string is a Valid Palindrome: O(n) two pointer solution explained

Problem Overview We are given a string s. The string consists of all printable ASCII characters. Goal is to check if the string is a palindrome — but first we need to remove non-alphanumeric characters, then check. A palindrome is a word or sentence if that reads the same backwards as forewords LeetCode - Valid Palindrome Example Input: s = "A man, a plan, a canal: Panama" Output: true Explanation: "amanaplanacanalpanama" is a palindrome. Input: s = "race a car" Output: false Explanation: "raceacar" is not a palindrome. ...

March 17, 2026 · 3 min · 509 words · Hitesh Patel