Problem 283016 · easy · Level 02 Linear Data Structures

Valid Palindrome

strings · two pointers · filtering

A palindrome reads the same forwards and backwards. Real sentences contain punctuation, spaces and mixed case, so the first job is to decide which characters count.

Given a string s, return True if it is a palindrome after converting all letters to lower case and removing every character that is not a letter or a digit. Otherwise return False. An empty string (after cleaning) is a palindrome.

Examples

Input:  s = "A man, a plan, a canal: Panama"
Output: True
Explanation: cleaned, it reads "amanaplanacanalpanama".
Input:  s = "race a car"
Output: False
Input:  s = " "
Output: True
Explanation: nothing is left after cleaning.

Constraints

  • 0 <= len(s) <= 10**4
  • s contains printable ASCII characters

Goals

  • Filter a string down to the characters that matter using str methods
  • Compare a sequence from both ends with two indices
Starting Python…