Check whether a phrase reads the same backwards

Write codeEasy10 minMeta style

Your task

A word puzzle site accepts a phrase as a palindrome when its letters and digits read the same in both directions. Spaces, punctuation and case do not count.

Write is_clean_palindrome(s) that returns whether s is a palindrome by that rule.

Input and output:

  • s: a string of 0 to 200,000 printable ASCII characters, codes 32 to 126.
  • Returns true or false.

Rules:

  • Keep only the letters a to z and A to Z and the digits 0 to 9. Ignore every other character, including spaces, punctuation and _.
  • Compare letters without regard to case, so A matches a. A digit matches only the same digit.
  • Return true when the kept characters read the same forwards and backwards.
  • A string with no letters or digits, including the empty string, returns true.

Examples

is_clean_palindrome(s: str) -> bool
Example 1
Inputis_clean_palindrome("A man, a plan, a canal: Panama")
OutputTrue
Example 2
Inputis_clean_palindrome("No 'x' in Nixon")
OutputTrue