EvalFrame Technical Mock Interviews & Coding Practice

Longest Palindrome

Easy · String · Algorithm problem · all problems

Given a string `s` which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters. Letters are case sensitive, for example, `"Aa"` is not considered a palindrome. **Examples:** ```typescript longestPalindrome("abccccdd") // 7 ("dccaccd") longestPalindrome("a") // 1 ```

Solve It in the BrowserPractice Explaining It Out Loud

Optimal Approach

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

Counting characters takes a single O(n) scan. The alphabet is bounded by 52 ASCII letters.

Follow-Up Questions Interviewers Ask About Longest Palindrome

  • Why can at most one odd-frequency character be included in the center?
    A palindrome is symmetric around its center. At most one character can occupy the center position with an odd count.

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.