diff --git a/minimum_number_of_pushes_to_type_word_ii.py b/minimum_number_of_pushes_to_type_word_ii.py new file mode 100644 index 0000000..4174ad8 --- /dev/null +++ b/minimum_number_of_pushes_to_type_word_ii.py @@ -0,0 +1,19 @@ +# https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-ii +from collections import Counter +from functools import reduce + +class Solution: + def minimumPushes(self, word: str) -> int: + cnt = Counter(word) + lst = sorted(cnt.values(), reverse=True) + push = 1 + ret = 0 + for i in range(0, len(lst), 8): + ret += reduce( + lambda x, y: x + y * push, + lst[i:i + 8 if i + 8 < len(lst) else len(lst)], + 0 + ) + push += 1 + return ret +