A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward.
Alphanumeric characters include letters (a-z, A-Z) and digits (0-9).
Given a string S, determine if it is a palindrome. Output YES if it is a palindrome, or NO otherwise.
S (1 ≤ length of S ≤ 100,000).YES if S is a valid palindrome, or NO otherwise.Input:
A man, a plan, a canal: Panama
Output:
YES
Explanation:
After removing non-alphanumeric characters and converting to lowercase, the string becomes "amanaplanacanalpanama", which reads the same forwards and backwards.
Input:
race a car
Output:
NO
Explanation:
After cleaning, the string is "raceacar", which is not a palindrome.
Case 1
race a car
NO
Case 2
A man, a plan, a canal: Panama
YES
Input
race a car
Expected Output
NO
Run or submit your code to see output here.