#K90542. Longest Palindrome Length
Longest Palindrome Length
Longest Palindrome Length
Given a string s
, determine the length of the longest palindrome that can be constructed by rearranging its characters. A palindrome is a string that reads the same forwards and backwards. The string may contain both uppercase and lowercase English letters. Your task is to compute the maximum possible length of a palindrome that can be formed using all or some of the characters in the string.
The length is computed by using as many pairs of characters as possible, and if any character remains unpaired, one of them can be used in the center of the palindrome.
Examples:
- Input: "abccccdd"; Output: 7
- Input: "a"; Output: 1
inputFormat
The input consists of a single line containing the string s
. The string contains only uppercase and/or lowercase English letters. It may be empty.
outputFormat
Output a single integer representing the length of the longest palindrome that can be formed from the characters of s
.
abccccdd
7