
Problem
Solution
Submissions
Valid Palindrome
Certification: Basic Level
Accuracy: 0%
Submissions: 0
Points: 5
Write a C program to determine if a string is a palindrome, considering only alphanumeric characters and ignoring cases. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). The function should return true if the string is a palindrome and false otherwise.
Example 1
- Input: s = "A man, a plan, a canal: Panama"
- Output: true
- Explanation: After filtering out non-alphanumeric characters and converting to lowercase: "amanaplanacanalpanama". This reads the same backward as forward, making it a palindrome.
Example 2
- Input: s = "race a car"
- Output: false
- Explanation: After filtering out non-alphanumeric characters and converting to lowercase: "raceacar". This does not read the same backward as forward, so it's not a palindrome.
Constraints
- 1 ≤ s.length ≤ 2 * 10^5
- s consists only of printable ASCII characters
- Time Complexity: O(n) where n is the length of the string
- Space Complexity: O(1) as we're doing it in-place
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Use two pointers technique, one starting from the beginning and one from the end
- Skip non-alphanumeric characters
- Convert each character to lowercase before comparison
- Compare characters from both ends moving inward
- Return false if any comparison fails, otherwise return true