Skip to content

Commit c32ea2f

Browse files
authored
Create 2268-minimum-number-of-keypresses.js
1 parent 2757785 commit c32ea2f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

2268-minimum-number-of-keypresses.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var minimumKeypresses = function (s) {
6+
const freq = Array(26).fill(0)
7+
const a = 'a'.charCodeAt(0)
8+
for (const e of s) {
9+
freq[e.charCodeAt(0) - a]++
10+
}
11+
let res = 0
12+
freq.sort((a, b) => b - a)
13+
14+
// console.log(freq)
15+
for (let i = 0; i < 26; i++) {
16+
if (freq[i] === 0) break
17+
const step = 1 + Math.floor(i / 9)
18+
const val = step * freq[i]
19+
res += val
20+
}
21+
22+
return res
23+
}

0 commit comments

Comments
 (0)