Practice Problem
Valid Palindrome
Difficulty: Easy
Determine if a string is a palindrome, considering only alphanumeric characters and ignoring cases.
Valid Palindrome
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. Alphanumeric characters include letters and numbers.
Given a string s, return true if it is a palindrome, or false otherwise.
Examples
Example 1:
Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: After removing non-alphanumeric characters and converting to lowercase,
"amanaplanacanalpanama" is a palindrome.Example 2:
Input: s = "race a car"
Output: false
Explanation: After processing, "raceacar" is not a palindrome.Example 3:
Input: s = " "
Output: true
Explanation: After removing non-alphanumeric characters, s is an empty string "".
An empty string reads the same forward and backward, so it is a palindrome.Constraints
1 <= s.length <= 2 * 10^5sconsists only of printable ASCII characters.
Expected Complexity
- Time: O(n)
- Space: O(1)
EASY
Two Pointers
Strings
Palindrome
Beginner
0 views
Solution
Hints
Hint 1
Hint 2
Premium
Hint 3
Premium
Hint 4
Premium
This section is available for CodeSnatch Premium members only.
