Categorygithub.com/szhou12/leetcode-goleetcode3137-Minimum-Number-of-Operations-to-Make-Word-K-Periodic
package
0.0.0-20241220224003-b7cf03a90b2b
Repository: https://github.com/szhou12/leetcode-go.git
Documentation: pkg.go.dev
# README
3137. Minimum Number of Operations to Make Word K-Periodic
Solution idea
- Any indices
i, j
to pick are divisible byk
. In other words,i, j
are multiples ofk
. Every substring has fixed lengthk
. Thus, we use a map to record each substring of lengthk
and its frequency. Find the substring of the highest frequencym
. The minimum number of operations =n/k - m
.
Time complexity = $O(n)$