Valid Palindrome Check

EASY

Check if a given string s is a palindrome (reads the same forwards and backward), ignoring case and non-alphanumeric characters.

Examples:

Example 1:

Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: After removing non-alphanumeric characters and converting to lowercase, 
it becomes "amanaplanacanalpanama", which is a palindrome.

Example 2:

Input: s = "race a car"
Output: false
Explanation: "raceacar" is not a palindrome.

Example 3:

Input: s = " "
Output: true
Explanation: An empty string (after filtering) is considered a palindrome.

Constraints:

  • 1 <= len(s) <= 2 * 105
  • s consists only of printable ASCII characters.

Function Signature (Python):

class Solution:
    def isPalindrome(self, s: str) -> bool:
        # Your code here
        pass

 

Nerchuko Academy · Free DS Interview Prep