All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : July 05, 2024
Last updated : July 05, 2024
Related Topics : Hash Table, String, Greedy, Sorting, Counting
Acceptance Rate : 71.14 %
This results in an
$O(n)$ despite the sorting due to it only sorting the counts of each letter meaning it sorts at most 26 values.
class Solution:
def minimumKeypresses(self, s: str) -> int:
output = 0
cnt = Counter(s)
mapped = 9
for v in sorted(cnt.values(), reverse=True) :
cost = mapped // 9
output += cost * v
mapped += 1
return output