Problems

Palindrome String

easy
easy
strings
two-pointers

Determine whether s is a palindrome after removing every non-alphanumeric character and comparing letters without regard to case.

Input / output

  • Input: s: string
  • Output: boolean

Examples

  1. "A man, a plan, a canal: Panama" returns true.
  2. "race a car" returns false.

Constraints

  • 0 <= s.length <= 200,000
  • Alphanumeric means the ASCII ranges A-Z, a-z, and 0-9.

Follow-up Can you solve it with two pointers and constant auxiliary space instead of building a cleaned copy?

Examples

Example 1

Input: s = "racecar"
Output: true

Example 2

Input: s = "a"
Output: true

Example 3

Input: s = "hello"
Output: false
🔒 5 hidden

Running will execute all 8 cases, including 5 hidden ones.