Imagine you have an old-school telephone keypad and need to type a word using T9-style input! ๐ฑ
You're given a string word containing distinct lowercase English letters. On a telephone keypad, each key (2-9) can be mapped to multiple letters. For example:
- Key 2 might have ["a","b","c"] - press once for "a", twice for "b", three times for "c"
- Key 3 might have ["d","e","f"] - press once for "d", twice for "e", etc.
The Challenge: You can remap the 8 keys (2-9) to any arrangement of letters you want! Each letter must be assigned to exactly one key, but keys can have different numbers of letters.
Goal: Find the minimum total number of key presses needed to type the entire word after optimally remapping the keys.
Key Insight: Since all letters in the word are distinct, this becomes an optimization problem about how to distribute letters across keys to minimize total presses!
Input & Output
Constraints
- 1 โค word.length โค 105
- word consists of distinct lowercase English letters
- The number of distinct letters is at most 26