Validate Palindrome
JavaScript
easy
10 mins
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 // Example 5: Input: "!!!@@@###" Output: true. // ignores all the non alphanumeric characters
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 🔥
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
