Skip to content
LC-3137 Medium LeetCode

3137. Minimum Number of Operations to Make Word K-Periodic

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

import collections


# freq table
class Solution(object):
    def minimumOperationsToMakeKPeriodic(self, word, k):
        """
        :type word: str
        :type k: int
        :rtype: int
        """
        cnt = collections.Counter(word[i:i+k]for i in xrange(0, len(word), k))
        return len(word)//k-max(cnt.itervalues())

Solution from kamyu104/LeetCode-Solutions · MIT