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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 59ms, memory 19.9MB, accepted 2026-01-01.
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