213. Longest Palindrome by Rearranging Characters

MediumStringString

Given a string s, return the length of the longest palindrome that can be built using its characters (each character used at most as many times as it appears). Letters are case-sensitive.

Input: A quoted string s.

Output: Integer — longest palindrome length.

Examples

Example 1
Input: "abccccdd"
Output: 7
Explanation: 'dccaccd' length 7.
Example 2
Input: "a"
Output: 1
Explanation: Single char.
Example 3
Input: "abc"
Output: 1
Explanation: Only one char can be the center.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →