
Problem 4: Longest Palindrome(easy)
Problem Statement:
Given a string, determine the length of the longest palindrome that can be constructed using the characters from the string. You don't need to return the palindrome itself, just its maximum possible length.
Examples:
-
- Input: "applepie"
- Expected Output: 5
- Justification: The longest palindrome that can be constructed from the string is "pepep", which has a length of 5. There are are other palindromes too but they all will be of length 5.
-
- Input: "aabbcc"
- Expected Output: 6
- Justification: We can form the palindrome "abccba" using the characters from the string, which has a length of 6.
-
- Input: "bananas"
- Expected Output: 5
- Justification: The longest palindrome that can be constructed from the string is "anana", which has a length of 5.
Constraints:
1 <= s.length <= 2000sconsists of lowercase and/or uppercase English letters only.
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory