Minimum Number of Pushes to Type Word II
Real-world version: Fewest Presses on a Letter PadThe statement here is our own: the same inputs, outputs and technique.
A pad has eight keys free for letters. Every one of the twenty-six letters is placed on exactly one key, and a key may hold any number of them in any order. A letter placed p-th on its key takes p presses each time it is typed.
Choose the arrangement that makes typing word cost as little as possible, and return that number of presses.
Examples
Example 1
- Input
- s = "abcdefghi"
- Output
- 10
Nine distinct letters are typed once each. Eight of them take a first place on the eight keys at one press apiece, and the ninth has to share a key, costing two.
Example 2
- Input
- s = "aaaaabbbbcccdde"
- Output
- 15
Only five distinct letters appear, so each gets a key to itself and every press costs one, giving the length of the word.
Example 3
- Input
- s = "zzzzzzzz"
- Output
- 8
One letter on its own key costs a single press each time.
Constraints
- 1 <= word.length <= 10^5
- word consists of lowercase English letters only
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def minimum_pushes(word: str) -> int:public int minimumPushes(String word)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 11 test cases: 11 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's