Skip to main content
Back to problems
Leetcode
Easy
Greedy
Arrays
Math
Minimum Number of Pushes to Type Word I

Minimize the number of button presses needed to type a word on an old-style phone keypad by assigning letters to keys optimally.

Acceptance 25%
Problem Statement

You are typing a word using a classic mobile phone keypad where each key can hold multiple letters. The first letter assigned to a key costs 1 press to type, the second costs 2 presses, and so on.

For this problem, assume you can place the letters of the word onto the available keys in any order you want. Your goal is to choose an arrangement that minimizes the total number of button presses required to type the entire word.

Compute the minimum possible number of presses needed to type the given word.

Input Format

  • A lowercase English string word.
  • Each character of word is a letter that must be typed once for each occurrence.

Output Format

  • Return an integer: the minimum total number of key presses required.

Constraints

  • 1 <= word.length <= 500
  • word contains only lowercase English letters.
Examples
Sample cases returned by the problem API.

Example 1

Input

word = "abcde"

Output

5

Explanation

All letters appear once, so each can be assigned to a first press on some key. Total presses = 1 + 1 + 1 + 1 + 1 = 5.

Example 2

Input

word = "aabbcc"

Output

6

Explanation

Each of the 6 characters can be arranged so every occurrence is typed with cost 1. Total presses = 6.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.