3014. Minimum Number of Pushes to Type Word I Easy
1/**
2 * [3014] Minimum Number of Pushes to Type Word I
3 *
4 * You are given a string word containing distinct lowercase English letters.
5 * Telephone keypads have keys mapped with distinct collections of lowercase English letters, which can be used to form words by pushing them. For example, the key 2 is mapped with ["a","b","c"], we need to push the key one time to type "a", two times to type "b", and three times to type "c" .
6 * It is allowed to remap the keys numbered 2 to 9 to distinct collections of letters. The keys can be remapped to any amount of letters, but each letter must be mapped to exactly one key. You need to find the minimum number of times the keys will be pushed to type the string word.
7 * Return the minimum number of pushes needed to type word after remapping the keys.
8 * An example mapping of letters to keys on a telephone keypad is given below. Note that 1, *, #, and 0 do not map to any letters.
9 * <img alt="" src="https://assets.leetcode.com/uploads/2023/12/26/keypaddesc.png" style="width: 329px; height: 313px;" />
10 *
11 * <strong class="example">Example 1:
12 * <img alt="" src="https://assets.leetcode.com/uploads/2023/12/26/keypadv1e1.png" style="width: 329px; height: 313px;" />
13 * Input: word = "abcde"
14 * Output: 5
15 * Explanation: The remapped keypad given in the image provides the minimum cost.
16 * "a" -> one push on key 2
17 * "b" -> one push on key 3
18 * "c" -> one push on key 4
19 * "d" -> one push on key 5
20 * "e" -> one push on key 6
21 * Total cost is 1 + 1 + 1 + 1 + 1 = 5.
22 * It can be shown that no other mapping can provide a lower cost.
23 *
24 * <strong class="example">Example 2:
25 * <img alt="" src="https://assets.leetcode.com/uploads/2023/12/26/keypadv1e2.png" style="width: 329px; height: 313px;" />
26 * Input: word = "xycdefghij"
27 * Output: 12
28 * Explanation: The remapped keypad given in the image provides the minimum cost.
29 * "x" -> one push on key 2
30 * "y" -> two pushes on key 2
31 * "c" -> one push on key 3
32 * "d" -> two pushes on key 3
33 * "e" -> one push on key 4
34 * "f" -> one push on key 5
35 * "g" -> one push on key 6
36 * "h" -> one push on key 7
37 * "i" -> one push on key 8
38 * "j" -> one push on key 9
39 * Total cost is 1 + 2 + 1 + 2 + 1 + 1 + 1 + 1 + 1 + 1 = 12.
40 * It can be shown that no other mapping can provide a lower cost.
41 *
42 *
43 * Constraints:
44 *
45 * 1 <= word.length <= 26
46 * word consists of lowercase English letters.
47 * All letters in word are distinct.
48 *
49 */
50pub struct Solution {}
51
52// problem: https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i/
53// discuss: https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i/discuss/?currentPage=1&orderBy=most_votes&query=
54
55// submission codes start here
56
57impl Solution {
58 pub fn minimum_pushes(word: String) -> i32 {
59 0
60 }
61}
62
63// submission codes end
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68
69 #[test]
70 fn test_3014() {
71 }
72}
73
Back
© 2025 bowen.ge All Rights Reserved.