Palindrome Checker

Difficulty: Easy · Topics: String, Two Pointers

Difficulty: Easy  |  Tags: String, Two Pointers

Description

Given a string s, determine if it is a palindrome after:

  • Converting all uppercase letters to lowercase.
  • Removing all non-alphanumeric characters.
  • An empty string is considered a palindrome.

    Implement:

    isPalindrome(s) → boolean
    

    Examples

    Example 1:

    Input:  "A man, a plan, a canal: Panama"
    Output: true
    Explanation: "amanaplanacanalpanama" is a palindrome.
    

    Example 2:

    Input:  "race a car"
    Output: false
    

    Example 3:

    Input:  " "
    Output: true
    

    Example 4:

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

    Constraints

    Hints

    Hint 1

    Two-pointer approach: one from start, one from end. Skip non-alphanumeric characters. Compare characters case-insensitively.

    Follow-up

    ---

    ## Testing & Edge Cases

    Practice this problem

    Related problems