Construct K Palindrome Strings - Problem
Given a string s and an integer k, determine whether you can use all the characters in s to construct exactly k non-empty palindrome strings.
A palindrome is a string that reads the same forward and backward. Return true if it's possible to construct k palindromes using all characters from s, otherwise return false.
Key constraints:
- You must use all characters from the input string
- Each palindrome must be non-empty
- You need exactly
kpalindromes
Input & Output
Example 1 — Basic Case
$
Input:
s = "annabelle", k = 2
›
Output:
true
💡 Note:
We can construct 2 palindromes: "anna" + "elble" or "anna" + "belle". Only one character 'b' has odd frequency, which is ≤ k=2.
Example 2 — Impossible Case
$
Input:
s = "leetcode", k = 3
›
Output:
false
💡 Note:
Characters l, t, c, o, d all have odd frequencies (1 each). That's 5 odd frequencies > k=3, so impossible.
Example 3 — Edge Case
$
Input:
s = "yzyzyzyzyzyzy", k = 2
›
Output:
true
💡 Note:
y appears 7 times, z appears 6 times. Only y has odd frequency, so 1 ≤ 2, possible.
Constraints
- 1 ≤ k ≤ 105
- 1 ≤ s.length ≤ 105
- s consists of lowercase English letters
Visualization
Tap to expand
Understanding the Visualization
1
Input
String s and integer k representing desired palindrome count
2
Process
Count character frequencies and identify odd counts
3
Output
True if odd frequencies ≤ k, false otherwise
Key Takeaway
🎯 Key Insight: At most k characters can have odd frequencies for k palindromes
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code