Alphanumeric Palindrome

The program must accept a string S as the input. The program must print YES if all the alphanumeric characters in the string S forms a palindrome. Else the program must print NO as the output.
Note: At least one alphanumeric character is always present in the string S.

Boundary Condition(s):
1 <= Length of S <= 100

Input Format:
The first line contains S.

Output Format:
The first line contains YES or NO.

Example Input/Output 1:
Input:
a#b#c@3cb=a

Output:
YES

Explanation:
The alphanumeric characters in the given string are a b c 3 c b a.
Here the alphanumeric characters forms a palindrome.
Hence the output is YES

Example Input/Output 2:
Input:
*R-ack+kca-r

Output:
NO

Example Input/Output 3:
Input:
***H2O@O-2-H**

Output:
YES

S=input().strip()
Req_String=''
for index in S:
    if index.isalpha():
        Req_String+=index
    if index.isnumeric():
        Req_String+=index
if Req_String==Req_String[::-1]:
    print("YES")
else:
    print("NO")

Leave a Reply

Your email address will not be published. Required fields are marked *

More posts. You may also be interested in.