Determine whether a string can be rearranged into exactly palindrome strings.
Given a string , you may rearrange its characters any way you like. Decide whether it is possible to split all characters of into exactly non-empty strings such that every string is a palindrome.
A palindrome reads the same forward and backward. Every character of must be used exactly once in the strings.
Input Format
- A string
s - An integer
k
Output Format
- Return
trueif the characters ofscan be rearranged into exactlykpalindrome strings. - Otherwise, return
false.
Constraints
scontains lowercase English letters
Example 1
Input
s = "annabelle", k = 2
Output
true
Explanation
One valid rearrangement is "anna" + "belle"? No, that second string is not a palindrome. A valid split after rearranging is "anna" and "belleb"? That uses too many characters. Instead, the characters can be rearranged into "anna" and "eblleb"; both are palindromes and use all letters exactly once.
Example 2
Input
s = "leetcode", k = 3
Output
false
Explanation
The string has too many characters with odd frequencies to form 3 palindrome strings after rearrangement.
Show 1 more example
Example 3
Input
s = "true", k = 4
Output
true
Explanation
Each character can form its own single-letter palindrome, so 4 palindromes are possible.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.