MCPcopy Create free account
hub / github.com/Rohit91singh9/Coding-DP-DSA / solution

Function solution

solution.py:3–18  ·  view source on GitHub ↗
(word)

Source from the content-addressed store, hash-verified

1from collections import Counter
2
3def solution(word):
4 charsCount = Counter(word)
5 mostCommonChars = charsCount.most_common()
6
7 keyPad = [[] for i in range(9)]
8 totalClickCounts = 0
9 currKeypadIndex = 1
10 for char, occ in mostCommonChars:
11 keyPad[currKeypadIndex - 1].append(char)
12 buttonPosition = keyPad[currKeypadIndex - 1].index(char) + 1 # since lists are 0-indexed and to avoid zero multiplication
13
14 totalClickCounts += occ * buttonPosition
15 currKeypadIndex = (currKeypadIndex + 1) % 9
16
17 print(keyPad)
18 return totalClickCounts
19
20word1 = "abacadefghibj"
21word2 = "abcghdiefjoba"

Callers 1

solution.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected