/125. Valid Palindrome

125. Valid Palindrome

Easy
Two Pointers52.9% acceptance

Given a string input_string, return True if, after converting all uppercase letters to lowercase and removing all non-alphanumeric characters, the resulting string reads the same forwards and backwards. Otherwise, return False.

Example 1

Input: "No lemon, no melon!"

Output: True

Explanation: After normalization: "nolemonnomelon" is a palindrome.

Example 2

Input: "123abccba321"

Output: True

Explanation: After normalization: "123abccba321" is a palindrome.

Example 3

Input: "Palindrome123"

Output: False

Explanation: After normalization: "palindrome123" is not a palindrome.

Constraints

  • 1 <= len(input_string) <= 200000
  • input_string consists only of printable ASCII characters
Python (current runtime)

Case 1

Input: "Was it a car or a cat I saw?"

Expected: True

Case 2

Input: "OpenAI 2024!"

Expected: False

Case 3

Input: "!@#$$#@!"

Expected: True

Case 4

Input: "Able was I, I saw Elba"

Expected: True

Case 5

Input: "Python3.8"

Expected: False