At Stripe, you need to validate whether a user-entered string reads the same forward and backward when punctuation, spaces, and other non-alphanumeric characters are ignored. Write an algorithm that returns whether the cleaned string is a palindrome.
Implement a function that takes a single string s and returns a boolean:
s — a string containing letters, digits, spaces, and special charactersTrue if the string is a palindrome after removing all non-alphanumeric characters and ignoring letter case; otherwise FalseExample 1
Input: s = "A man, a plan, a canal: Panama"
Output: True
Explanation: After filtering and lowercasing, the string becomes "amanaplanacanalpanama", which is the same forward and backward.
Example 2
Input: s = "race a car"
Output: False
Explanation: The cleaned string is "raceacar", which is not a palindrome.
0 <= len(s) <= 2 * 10^5s may contain uppercase and lowercase English letters, digits, spaces, and punctuationAim for a linear-time solution. A two-pointer approach is preferred because it avoids building a separate cleaned string.