Skip to content
LC-3016 Medium LeetCode

3016. Minimum Number of Pushes to Type Word II

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 80% Topics: Hash Table, String, Greedy, Sorting, Counting
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(26)

import collections


# freq table, greedy
class Solution(object):
    def minimumPushes(self, word):
        """
        :type word: str
        :rtype: int
        """
        return sum(x*(i//(9-2+1)+1) for i, x in enumerate(sorted(collections.Counter(word).itervalues(), reverse=True)))

Solution from kamyu104/LeetCode-Solutions · MIT