Longest Palindrome from Letters
EasyGreedygreedy
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given a string s of uppercase and lowercase English letters. Using each character of s at most once, in any order you like, build the longest possible palindrome.
Return the length of that palindrome (not the palindrome itself). Letters are case-sensitive, so "A" and "a" are different characters.
Examples
Input: s = "abccccdd"
Output: 7
One longest palindrome is "dccaccd": the pairs cc, cc, dd are mirrored and one leftover letter sits in the middle.
Input: s = "a"
Output: 1
A single letter is already a palindrome.
Input: s = "Aa"
Output: 1
A and a differ, so only one of them can be used.
Constraints
- 1 <= s.length <= 2000
- s consists of uppercase and lowercase English letters only
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.