Facebook Pixel

Validate Palindrome

JavaScript
easy

Write a function that determines whether a given string is a valid palindrome. A palindrome is a word, phrase, or sequence that reads the same backward as forward. Ignore cases and all non-alphanumeric characters.

Input: A single string str.

Output: Return true if the string is a valid palindrome, false otherwise.

Example Inputs & Outputs

// Example 1: Input: "A man, a plan, a canal: Panama" Output: true // Example 2: Input: "race a car" Output: false // Example 3: Input: " " Output: true // Example 4: Input: "1234" Output: false

Constraints & Edge Cases

  • The input string may contain letters, numbers, spaces, and special characters.
  • Ignore cases (treat uppercase and lowercase the same).
  • Ignore all non-alphanumeric characters.
  • An empty string or a string with only non-alphanumeric characters is considered a valid palindrome.

Companies:

amazon
tcs
paytm

Solve Similar questions 🔥