Loading practice problems…
Loading your practice workspace…
Loading code editor…
4 / 29
Sign in
Algorithms/Two Pointers

Valid Palindrome

easy20 min

A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing every non-alphanumeric character, it reads the same forward and backward.

Given a string s, return true when it is a palindrome and false otherwise.

Example 1

Inputs = "A man, a plan, a canal: Panama"

Outputtrue

Removing spaces and punctuation and using lowercase gives amanaplanacanalpanama, which reads the same in both directions.

Example 2

Inputs = "race a car"

Outputfalse

Removing spaces gives raceacar. Its middle characters are e and a, which do not match.

Constraints

  • 1 ≤ s.length ≤ 200,000
  • s contains printable ASCII characters.
Two PointersStrings