2268. Minimum Number of Keypresses

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2268

class Solution:
    def minimumKeypresses(self, s: str) -> int:
        cnt = Counter(s)
        res = 0
        i, j = 0, 1
        for v in sorted(cnt.values(), reverse=True):
            i += 1
            res += j * v
            if i % 9 == 0:
                j += 1
        return res