Ctrl K

Split Letters Into Palindromes

Medium
You have a set of letters letters (a string of lowercase English letters) and a number count. Can you distribute **all** the letters among exactly count non-empty strings so that each string is a palindrome, reading the same forwards and backwards? The order of the letters in letters does not matter: you may rearrange them freely. Return True if this is possible, otherwise False.
Example 1
letters="racecar", count=3 → True

For example rcr, aea and c: every letter is used and all three are palindromes.

Example 2
letters="abcde", count=3 → False

All five letters appear once, and a palindrome can hold at most one unpaired letter. Three palindromes are not enough for five unpaired letters.

Example 3
letters="zz", count=3 → False

Two letters cannot make three non-empty strings.

Constraints
  • 1 ≤ len(letters) ≤ 10⁵
  • letters consists of lowercase English letters
  • 1 ≤ count ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsNo Twin Letters Side by Side MediumPalindrome From Two-Letter Cards MediumLargest String With a Run Cap MediumNine-Button Layout MediumBiggest Palindrome From Digits Medium
loading Python…
Input
letters="racecar", count=3
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 102 tests on the server, hidden ones included.