Skip to content

Commit 800294c

Browse files
authored
Create 3137-minimum-number-of-operations-to-make-word-k-periodic.js
1 parent c597f2f commit 800294c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {string} word
3+
* @param {number} k
4+
* @return {number}
5+
*/
6+
var minimumOperationsToMakeKPeriodic = function (word, k) {
7+
const n = Math.floor(word.length / k)
8+
const map = new Map()
9+
10+
for (let i = 0; i < word.length; i += k) {
11+
const sub = word.substring(i, i + k)
12+
map.set(sub, (map.get(sub) || 0) + 1)
13+
}
14+
15+
return n - Math.max(...map.values())
16+
}

0 commit comments

Comments
 (0)