...

/

Valid Palindrome

Valid Palindrome

Try to solve the Valid Palindrome problem.

Statement

Given a string, s, return TRUE if it is a palindrome; otherwise, return FALSE.

A phrase is considered a palindrome if it reads the same backward as forward after converting all uppercase letters to lowercase and removing any characters that are not letters or numbers. Only alphanumeric characters (letters and digits) are taken into account.

Constraints:

  • 11 \leq s.length 3000\leq 3000

  • s consists only of printable ASCII characters.

Examples

canvasAnimation-image
1 / 7

Understand the problem

Let’s take a moment to make sure you've correctly understood the problem. The quiz below helps you check if you're solving the correct problem:

Valid Palindrome

1.

What is the output for the following input?

s = “A man, a plan, a canal: Panama”

A.

TRUE

B.

FALSE


1 / 5

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding on how to solve this problem.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4
5

Try it yourself

Implement your solution in the following coding playground.

Need a nudge?

Explore these hints—each one is designed to guide you a step closer to the solution.

JavaScript
usercode > Solution.js
function isPalindrome(s) {
let left = 0, right = s.length - 1;
while (left < right) {
while (left < right && !/[a-zA-Z0-9]/.test(s[left])) {
left++;
}
while (left < right && !/[a-zA-Z0-9]/.test(s[right])) {
right--;
}
if (s[left].toLowerCase() !== s[right].toLowerCase()) {
// write your code here
}
left++;
right--;
}
return true;
}
export { isPalindrome };
Valid Palindrome

Access this course and 1200+ top-rated courses and projects.