Imagine you have a collection of letter tiles, each with either a lowercase or uppercase letter. Your task is to build the longest possible palindrome using these tiles!
A palindrome reads the same forwards and backwards, like "racecar" or "A man a plan a canal Panama" (ignoring spaces). However, in this problem, case matters - so "Aa" is not a palindrome because uppercase 'A' and lowercase 'a' are different characters.
Goal: Given a string s containing letters, return the length of the longest palindrome you can construct using those letters.
Example: With letters "abccccdd", you can build "dccaccd" (length 7) by using pairs of letters symmetrically and putting one odd-count letter in the middle.
Input & Output
Visualization
Time & Space Complexity
Single pass through the string to count frequencies, then O(k) to process counts where k โค min(n, 128) for ASCII
Hash table stores at most k unique characters where k โค min(n, 128) for ASCII characters
Constraints
- 1 โค s.length โค 2000
- s consists of lowercase and/or uppercase English letters only
- Case sensitive: 'A' and 'a' are considered different characters