Problem 4
Palindrome Check
Easy · 10 pts · String, Two Pointers
Problem
You are given a string. Decide whether it is a palindrome, meaning it reads the same forwards and backwards. Before comparing, ignore letter case (treat 'A' and 'a' as the same) and skip every character that is not a letter or a digit, such as spaces, commas and other punctuation. A string that is empty, or becomes empty after this filtering, counts as a palindrome. Two pointers, one moving forward from the start and one moving backward from the end, can check this without building a new string.
Input
A single line containing the input string.
Output
Print true if the string is a palindrome; otherwise print false.
Constraints
The input string contains at most 100000 characters.
Example input
Madam
Example output
true
Explanation
The string is "Madam". Ignoring case it becomes "madam", which reads m-a-d-a-m in both directions, so the answer is true.