Skip to content

Latest commit

 

History

History
45 lines (31 loc) · 1.09 KB

_2268. Minimum Number of Keypresses.md

File metadata and controls

45 lines (31 loc) · 1.09 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


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.


Solutions

Python

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