Challenge: Palindrome Sentence

Lab Python Beginner 10 points

Read a sentence. Ignoring spaces, punctuation and capital letters, is it a palindrome? Use two pointers that skip anything that isn't a letter or digit. Print yes or no.

Input

One line of text.

Output

yes or no.

Example

Input

A man, a plan, a canal: Panama

Output

yes
Sample input available Sample output available
Editor
Python

Hints

ch.isalnum() is True for letters and digits.

Compare with .lower() so A and a match.

If a side points at a space or comma, just move that pointer.

Solution explanation

The pointers skip junk characters and compare letters, in one pass: O(n) time, O(1) space.

Show solution
s = input()
left, right = 0, len(s) - 1
ok = True
while left < right:
    if not s[left].isalnum():
        left += 1
    elif not s[right].isalnum():
        right -= 1
    elif s[left].lower() != s[right].lower():
        ok = False
        break
    else:
        left += 1
        right -= 1
print("yes" if ok else "no")
Output
Answer
HOME LABS COMMUNITY DASHBOARD