312. Longest Palindrome
Easy
Frequency Parity
Hashing
Problem
Given a string s containing lowercase and uppercase English letters, return the length of the longest palindrome that can be built using those characters. Character matching is case-sensitive.
Examples
Example 1
Input: "abccccdd"
Output: 7
Example 2
Input: "a"
Output: 1
Example 3
Input: "Aa"
Output: 1
Constraints
� 1 <= s.length <= 2000
� s contains lowercase and uppercase English letters.
Hints
?? Every even frequency can be used completely.
?? For an odd frequency, use the largest even portion.
?? At most one odd-frequency character can contribute one extra center character.
Expected Complexity
Time: O(n)
Space: O(k)
Follow-up
Can you compute the answer while counting characters in a single pass?
Practice Notes
Attempts: 0
Time spent: 0min
Hints used: 0
JavaScript
00:00
Loading...
Case 1
Case 2
Case 3
Input
"abccccdd"Expected
7