easyTwo PointersPure DSA~15 min
Config Token Palindrome
A config linter flags 'mirror tokens' — identifiers that read the same forwards and backwards once you ignore case and any non-alphanumeric separators. Given a raw token string, decide whether it is a mirror token.
Problem
Given a string s, return true if it is a palindrome considering only alphanumeric characters and ignoring case, otherwise false.
Input
A string s of length n (1 ≤ n ≤ 2·10^5) containing printable ASCII.
Output
A boolean — true if s is a palindrome under the stated rules.
Constraints
- 1 ≤ n ≤ 200,000
- s may contain letters, digits, spaces, and punctuation
- Comparison is case-insensitive and ignores non-alphanumeric characters
Examples
Example 1
Input
s = "Race-Car_1 1"
Output
false
Filtered and lowercased: 'racecar11'. Reversed: '11racecar'. They differ, so it is not a palindrome.
Example 2
Input
s = "A man, a plan: a canal — Panama"
Output
true
Filtered and lowercased: 'amanaplanacanalpanama', which reads identically backwards.