Leetcode 1502 Solution
This article provides solution to leetcode question 1502 (construct-k-palindrome-strings)
Access this page by simply typing in "lcs 1502" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/construct-k-palindrome-strings
Solution
class Solution:
def canConstruct(self, s: str, k: int) -> bool:
m = collections.defaultdict(int)
for ch in s:
m[ch] += 1
odd_cnt = 0
for val in m.values():
if val % 2 == 1:
odd_cnt += 1
return odd_cnt <= k and k <= len(s)