Longest Palindrome

Given a string s made of lowercase and uppercase English letters, return the length of the longest palindrome you can build using its letters. Letters are case sensitive, so "Aa" is not a palindrome.

30:00

Longest Palindrome
easy
Free written solution
Topics
Companies

Given a string s made of lowercase and uppercase English letters, return the length of the longest palindrome you can build using its letters. Letters are case sensitive, so "Aa" is not a palindrome.

Example 1:
Input: {"s":"abccccdd"}
Output: 7
Constraints:
  • 1≤s.length≤20001 \leq \text{s.length} \leq 2000

  • ss consists of lowercase and/or uppercase English letters only.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"s":"abccccdd"}

Count 'a': its bin now holds 1.

s

counted 1/8

a

b

c

c

c

c

d

d

Letter counts

paired

leftover

middle

a

x1

Palindrome built from both ends

length = 0

|

Variables
VariableValue
counted1
distinct1
DepthFunction Call
Stack empty
0/15