Loading...
You are given a string s of printable ASCII characters. Reduce it to its filtered form by applying two rules: keep only the alphanumeric characters (the letters a to z and A to Z and the digits 0 to 9, discarding everything else), and replace every uppercase letter with its lowercase counterpart.
Return true if the filtered form is a palindrome, meaning it reads the same from left to right as it does from right to left, and false otherwise.
If nothing survives the filtering, the filtered form is the empty string, which reads the same in both directions and therefore counts as a palindrome.
Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: The filtered form is "amanaplanacanalpanama", which is the same read backwards.
Input: s = "race a car"
Output: false
Explanation: The filtered form is "raceacar", which reads "racaecar" backwards.
Input: s = " "
Output: true
Explanation: The space is not alphanumeric, so the filtered form is empty and counts as a palindrome.
s.length ≤2⋅105s consists only of printable ASCII characters.Click "Run" to test with sample cases or "Submit" to run all tests.