Blind 75
9 / 75Free practice

Valid Palindrome

Easy · Two pointers

Jump to code

Check whether a string reads the same in both directions after ignoring non-alphanumeric characters and letter case. An empty cleaned string counts as a palindrome.

Examples

Example 1

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

Output: true

Example 2

s = "race a car"

Output: false

Constraints

  • 1 <= s.length <= 1000
  • s is made up of only printable ASCII characters.
Need a hint?

You can skip punctuation without building a cleaned copy.

Asked in real interviews

Candidates reported versions of Valid Palindrome from these company interviews. Some company questions are locked and open with Premium or XP.

Browse all real coding interview questions

Accepted submissions mark this problem complete. Progress stays in this browser.

Run checks 5 examples. Submit checks all 8 cases. A free account runs this problem; no XP needed.
Language
Case 1
Input
[
  "A man, a plan, a canal: Panama"
]
Expected
true
Case 2
Input
[
  "race a car"
]
Expected
false
Case 3
Input
[
  " "
]
Expected
true
Case 4
Input
[
  "No lemon, no melon"
]
Expected
true
Case 5
Input
[
  "0P"
]
Expected
false

Drafts are saved per language in this browser when storage is available.