Ctrl K

Your Own Keypad Layout

Easy
On a push-button phone, letters are typed with keys 2 to 9: if a key holds several letters, the first takes one tap, the second two taps, the third three, and so on. You get to decide which letters go on which keys and in what order. Each letter must sit on exactly one key, and a key may hold any number of letters. Given a string word of distinct lowercase English letters, return the fewest total taps needed to type it with the best layout.
Example 1
word="plan" → 4

Each of the four letters can go first on its own key, one tap each.

Example 2
word="abcdefghij" → 12

Eight letters take the first slot on keys 2–9 (8 taps) and two more take a second slot (2 taps each): 8 + 4 = 12.

Constraints
  • 1 ≤ len(word) ≤ 26
  • word consists of lowercase English letters
  • All letters of word are distinct
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Biggest Odd Chunk EasyLargest Odd Bit Shuffle EasyRound Prices to a Total MediumCross Swaps of x and y MediumLucky Ticket With Blanks Medium
loading Python…
Input
word="plan"
Expected
4

Run checks the first 3 tests in your browser. Submit checks all 184 tests on the server, hidden ones included.