17. Valid Palindrome
easyAsked at ZoomDetermine if a string is a palindrome considering only alphanumerics.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Problem
Given a string s, return true if it is a palindrome after converting to lowercase and removing non-alphanumeric characters. Spaces, punctuation, and case must be ignored.
Constraints
1 <= s.length <= 2 * 10^5ASCII printable characters
Examples
Example 1
s="A man, a plan, a canal: Panama"trueExample 2
s="race a car"falseApproaches
1. Normalize then reverse
Filter to alphanumerics, lowercase, reverse and compare.
- Time
- O(n)
- Space
- O(n)
const c=s.toLowerCase().replace(/[^a-z0-9]/g,''); return c===c.split('').reverse().join('');Tradeoff:
2. Two-pointer in-place
Walk from both ends, skipping non-alphanumeric, comparing lowercase chars.
- Time
- O(n)
- Space
- O(1)
function isPalindrome(s) {
const ok = (c) => /[a-z0-9]/i.test(c);
let i = 0, j = s.length - 1;
while (i < j) {
while (i < j && !ok(s[i])) i++;
while (i < j && !ok(s[j])) j--;
if (s[i].toLowerCase() !== s[j].toLowerCase()) return false;
i++; j--;
}
return true;
}Tradeoff:
Zoom-specific tips
Zoom values minimal-allocation string parsing because chat messages and meeting topics are validated on hot paths — show the two-pointer version first.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
Practice these live with InterviewChamp.AI
Drill Valid Palindrome and other Zoom interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →