Longest Palindrome
EasyPython 3StringsHash tables
You are given a string s. By removing and rearranging its characters, build the longest palindrome possible and return it. If several palindromes share the maximum length, returning any one of them is acceptable.
Constraints: - 0 <= len(s) - characters may repeat
Examples: "aha" -> "aha" (length 3) "abc" -> "a" (any single character) "gggaaa" -> "agaga" (length 5; one leftover unused) "aabb" -> "abba" (length 4, no center char) "" -> ""
Python 3, run in your browser. Run tests runs the problem's own tests with a free account; the AI interviewer reads your code and your runs in a practice interview.
Loading the editor…