Trains the technique from
LeetCode 3016Minimum Number of Pushes to Type Word IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
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.
Example 1
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
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
One letter on its own key costs a single press each time.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def minimum_pushes(word: str) -> int:public int minimumPushes(String word)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.