Two pointers and sliding window · Problem 1 of 3

Palindrome check that ignores punctuation

Pattern: Valid Palindrome with Two Pointers

easyNot solved yet

The problem

Write a function that returns whether text reads the same forwards and backwards when you only look at letters and digits and ignore upper/lower case. Spaces, punctuation and other symbols don't count.

Letters are the English letters a–z (in either case), and digits are 0–9. Try to use O(1) extra space: no cleaned-up copy of the string.

text
1is_clean_palindrome("Was it a car, or a cat I saw?")  ->  True
2is_clean_palindrome("No 'x' in Nixon")                ->  True
3is_clean_palindrome("race a car")                     ->  False
4is_clean_palindrome("?!")                             ->  True

The last example has no letters or digits at all, which counts as a palindrome (an empty string reads the same both ways).

Write is_clean_palindrome(text) in Python or isCleanPalindrome(text) in JavaScript. Examples are written in Python: in JavaScript, None is null and True / False are true / false.

Runs privately in your browser. Nothing is sent to a server.Ctrl/⌘ + Enter to run · Esc then Tab to leave the editor

Write your function, then run it against 22 tests.

Breakdown

Stuck? Reveal one step at a time, and try again after each one.

  1. Step 2
  2. Step 3
  3. Step 4

Solution

?

Give it a real try first: you learn far more from a wrong attempt than from reading the answer.