Valid Palindrome
Two PointersEasy
Step 1 of 8 · Understand
1. Understand the problem
Problem statement
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Given a string s, return true if it is a palindrome, or false otherwise.
Input
A string `s` that may contain letters, digits, spaces, and punctuation.
Output
A boolean. `true` if the cleaned string is the same forwards and backwards, `false` otherwise.
Examples
input → s = "A man, a plan, a canal: Panama"
output → true
After stripping non-alphanumeric chars and lowercasing: "amanaplanacanalpanama", a palindrome.
input → s = "race a car"
output → false
Cleaned: "raceacar", not the same forwards and backwards.
input → s = " "
output → true
Empty after cleaning, an empty string is a palindrome.
Write your solution above and hit Run tests. Results and tips appear here.