Skip to content
Decoder

Valid Palindrome

Easy

Problem

A phrase is a palindrome if it reads the same forwards and backwards once you lowercase every letter and throw away everything that is not a letter or digit. Given a string s, return true if it is a palindrome.

Example 1

Input
"A man, a plan, a canal: Panama"
Output
true
Why
"amanaplanacanalpanama"

Example 2

Input
"race a car"
Output
false
Why
"raceacar"

Example 3

Input
" "
Output
true
Why
nothing left, which counts

Try to solve it without building a cleaned-up copy of the string.

Constraints

  • 0 <= s.length <= 2 * 10^5
  • s contains only printable ASCII characters.
  • Use O(1) extra space.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.