Two PointersAI-assisted round
Check if a string is a palindrome
Return true if a string reads the same forward and backward, considering only letters and digits and ignoring case. Return false otherwise.
AIThe assistant proposed this solution
“I strip out everything that isn't a letter or digit, then walk two pointers in from both ends comparing characters. If they ever disagree it's not a palindrome. Clean and linear.”
1function isPalindrome(s) {
2 const clean = [...s].filter((c) => /[a-z0-9]/i.test(c));
3 let left = 0, right = clean.length - 1;
4 while (left < right) {
5 if (clean[left] !== clean[right]) return false;
6 left++;
7 right--;
8 }
9 return true;
10}
Before you accept this, make the call. What's your verdict?