Find the minimum number of character changes needed so a word becomes k-periodic.
Given a lowercase word and an integer , make the word k-periodic by changing as few characters as possible.
A word is k-periodic if every character at positions that differ by a multiple of is the same. Equivalently, for each residue class modulo , all characters in those positions must match.
Your task is to compute the minimum number of operations required, where one operation changes a single character to any other lowercase letter.
word consisting of lowercase English letters.k.You may assume the inputs describe a valid instance of the problem.
word k-periodic.1 <= k <= len(word)word contains only lowercase English lettersExample 1
Input
word = "leetcode", k = 2
Output
4
Explanation
Positions 0,2,4,6 are l,e,c,d and positions 1,3,5,7 are e,t,o,e. In each group, keep the most frequent letter and change the others. The minimum total changes is 4.
Example 2
Input
word = "aaabbb", k = 3
Output
0
Explanation
Positions grouped by modulo 3 are a,b, a,b, a,b. Each group already has matching characters after considering the repeating pattern, so no changes are needed.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.