Asked at

Valid Palindrome

Easy
Verified
StringTwo Pointers~15 min

Return whether s is a palindrome when you consider only alphanumeric characters and ignore case.

Filter to lowercase alphanumerics, then compare with two pointers walking inward from both ends. The input arrives as a single string s.

Examples

in"A man, a plan, a canal: Panama"
outtrue

Ignoring case and non-alphanumerics, it reads "amanaplanacanalpanama".

in"race a car"
outfalse

"raceacar" is not a palindrome.

Constraints

  • 1 ≤ s.length ≤ 2·10⁵
  • s consists of printable ASCII characters.

Get help

🔑

Sign in to solve

Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.