Valid Palindrome

Easy#125towards each other

You get a string. Find out whether it reads the same left to right and right to left once you keep only the letters and digits and ignore upper and lower case. Our example: "Taco, cat!" — yes, it is a palindrome.

input
s: a string of letters, digits, spaces and punctuation.
returns
true if s reads the same both ways once every character that is not a letter or a digit is dropped and uppercase letters are made lowercase; otherwise false.
constraints
  • 1 ≤ s.length ≤ 5000
  • s: printable ASCII characters
our 14 tests keep to them
examples
Open a test in the tests panel: it shows the input and the expected answer.
/**
 * @param {string} s
 * @return {boolean}
 */
function isPalindrome(s) {

}
Ctrl ↵
format
reset

saved in this browser

14 tests · limit 3 s

Stuck?

See the solution run step by step on our example, then why it works and its complexity.

Watch the walkthrough →

Next: more two pointers problems

Pattern “Two pointers” →

The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.