You are given a single line of text. Keep only its alphanumeric characters (letters and digits), treat uppercase and lowercase letters as equal, and ignore everything else (spaces, punctuation).
Decide whether the resulting sequence of characters reads the same left-to-right as right-to-left.
One line: a string s (it may contain letters, digits, spaces and punctuation; it may be empty).
Print YES if the cleaned string is a palindrome, otherwise NO. An empty cleaned string counts as a palindrome.
s contains printable ASCII characters.Example 1
Input
A man, a plan, a canal: Panama
Expected
YES
Explanation
Keeping letters and digits and lowercasing gives 'amanaplanacanalpanama', which is a palindrome, so the answer is YES.
Example 2
Input
Hello, World!
Expected
NO
Explanation
Cleaned it becomes 'helloworld', which reversed is 'dlrowolleh' - not the same - so the answer is NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →