Strings String basics
129. Longest Palindrome
You are given a string s of English letters. Build the longest palindrome you can from its letters, and return
its length. Each letter can be used at most as many times as it appears in s, and the letters can go in any
order. You do not have to use them all.
A palindrome reads the same from left to right and from right to left, such as "level" or "abba".
Uppercase and lowercase letters are different letters, so "Aa" is not a palindrome.
Example 1
Input: s = "bananas"
5Explanation: "anbna" is one longest palindrome. It uses two of the three as, both ns, and the b in the middle.
Example 2
Input: s = "Noon"
3Explanation: N and n are different letters. "oNo" uses both os, with N in the middle.
Example 3
Input: s = "pqrs"
1Explanation: No letter appears twice, so the best is a single letter, such as "q".
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ s.length ≤ 105sholds lowercase and uppercase English letters only.
Clarifying questions
What you would ask an interviewer before writing any code.