Skip to content

Commit bdfd497

Browse files
authored
Create 1297-maximum-number-of-occurrences-of-a-substring.js
1 parent 887d465 commit bdfd497

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @param {string} s
3+
* @param {number} maxLetters
4+
* @param {number} minSize
5+
* @param {number} maxSize
6+
* @return {number}
7+
*/
8+
function maxFreq(s, maxLetters, k, maxSize) {
9+
let count = new Map();
10+
for (let i = 0; i <= s.length - k; i++) {
11+
let substring = s.slice(i, i + k);
12+
if (!count.has(substring)) {
13+
count.set(substring, 0);
14+
}
15+
count.set(substring, count.get(substring) + 1);
16+
}
17+
let maxFreq = 0;
18+
for (let [substring, freq] of count) {
19+
if (new Set(substring).size <= maxLetters) {
20+
maxFreq = Math.max(maxFreq, freq);
21+
}
22+
}
23+
return maxFreq;
24+
}

0 commit comments

Comments
 (0)