LeetCode solutions

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

My accepted Python solution to LeetCode problem 3384, Minimum Number of Operations to Make Word K-Periodic, running in 59ms.

  • Difficulty: Medium
  • Python
  • Runtime 59ms
  • Memory 19.9MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 59ms, memory 19.9MB, accepted 2026-01-01.

python
class Solution:
    def minimumOperationsToMakeKPeriodic(self, word: str, k: int) -> int:
        n = len(word)
        chunks = {}
        for i in range(0, n, k):
            chunk = word[i:i+k]
            chunks[chunk] = chunks.get(chunk, 0) + 1
        max_freq = max(chunks.values())
        return n // k - max_freq

Source