Skip to content

Files

Latest commit

Zanger67/leetcodeZanger67/leetcode
Zanger67/leetcode
and
Zanger67/leetcode
Mar 16, 2025
03398f8 · Mar 16, 2025

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.21 %


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