DSA problem
Check if a String is a Palindrome
Given a string s, check whether it reads the same forward and backward. Ignore case and consider only alphanumeric characters.
Use two pointers starting from both ends. Skip non-alphanumeric characters, compare characters in a case-insensitive manner, and move inward. If all compared characters match, it is a palindrome. The ignore-non-alphanumeric part is what makes this interesting in interviews - A man, a plan, a canal: Panama is a palindrome once you strip punctuation and spaces. This teaches character classification and input sanitization, which is essential in real-world input validation. A follow-up: what about Unicode? In practice you would handle multi-byte characters and normalization, but for interview purposes ASCII is sufficient.
Examples
s = "A man, a plan, a canal: Panama"trues = "race a car"falseConstraints
- 1 <= s.length <= 10^5
3 hints and a full solution walkthrough with step-by-step visualizations are available in the practice editor.