You are given a string that may contain letters, digits, spaces, and punctuation. The task is to decide whether the string reads the same forward and backward once you ignore everything that is not a letter or a digit, and once you treat uppercase and lowercase letters as equal.
Return true when the cleaned-up version of the string is a palindrome, and false otherwise. An empty string (after filtering) counts as a palindrome.
Example 1
Input: s = "A man, a plan, a canal: Panama"
Output: true
After removing punctuation and spaces and lowercasing, the text becomes "amanaplanacanalpanama", which mirrors itself.
Example 2
Input: s = "race a car"
Output: false
The filtered text "raceacar" differs when read backward, so it is not a palindrome.
Constraints
1 ≤ s.length ≤ 2 * 10^5s consists only of printable ASCII characters.See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI