Skip to content
LC-1400 Medium LeetCode

1400. Construct K Palindrome Strings

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 69% Topics: Hash Table, String, Greedy, Counting
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

import collections


class Solution(object):
    def canConstruct(self, s, k):
        """
        :type s: str
        :type k: int
        :rtype: bool
        """
        count = collections.Counter(s)
        odd = sum(v%2 for v in count.itervalues())
        return odd <= k <= len(s)

Solution from kamyu104/LeetCode-Solutions · MIT