EvalFrame Technical Mock Interviews & Coding Practice

Valid Palindrome

Easy · Two Pointers · Algorithm problem · all problems

Determine whether a given string is a palindrome, considering only alphanumeric characters (letters and digits) and ignoring case. **Examples:** ```typescript isPalindrome("A man, a plan, a canal: Panama") // true isPalindrome("race a car") // false isPalindrome(" ") // true ```

Solve It in the BrowserPractice Explaining It Out Loud

Optimal Approach

  • Time complexity: O(n)
  • Space complexity: O(1)

The two pointers "left" and "right" traverse the string inward. Each character is visited at most once, giving an O(n) linear scan where n is string length.

Follow-Up Questions Interviewers Ask About Valid Palindrome

  • How would you solve this without the built-in .toLowerCase() function?
    You can check ASCII codes directly. If a character code is between 65 and 90 (uppercase A-Z), you can convert it to lowercase by adding 32 before comparing, or compare both uppercase and lowercase offsets directly in O(1).
  • What is the main drawback of the .replace().split().reverse().join() approach?
    The reverse-string approach allocates several intermediate objects: a lowercased string, a regex-replaced string, an array of characters, and a reversed string. This requires O(n) auxiliary memory and cannot short-circuit on the very first mismatched character.
  • How would you adapt this algorithm if you needed to check if a Linked List is a palindrome?
    You would use fast and slow pointers to find the middle of the linked list, reverse the second half in-place, and then compare node values starting from both ends.

Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.