1974. Minimum Time to Type Word Using Special Typewriter Easy
1/**
2 * [1974] Minimum Time to Type Word Using Special Typewriter
3 *
4 * There is a special typewriter with lowercase English letters 'a' to 'z' arranged in a circle with a pointer. A character can only be typed if the pointer is pointing to that character. The pointer is initially pointing to the character 'a'.
5 * <img alt="" src="https://assets.leetcode.com/uploads/2021/07/31/chart.jpg" style="width: 530px; height: 410px;" />
6 * Each second, you may perform one of the following operations:
7 *
8 * Move the pointer one character counterclockwise or clockwise.
9 * Type the character the pointer is currently on.
10 *
11 * Given a string word, return the minimum number of seconds to type out the characters in word.
12 *
13 * Example 1:
14 *
15 * Input: word = "abc"
16 * Output: 5
17 * Explanation:
18 * The characters are printed as follows:
19 * - Type the character 'a' in 1 second since the pointer is initially on 'a'.
20 * - Move the pointer clockwise to 'b' in 1 second.
21 * - Type the character 'b' in 1 second.
22 * - Move the pointer clockwise to 'c' in 1 second.
23 * - Type the character 'c' in 1 second.
24 *
25 * Example 2:
26 *
27 * Input: word = "bza"
28 * Output: 7
29 * Explanation:
30 * The characters are printed as follows:
31 * - Move the pointer clockwise to 'b' in 1 second.
32 * - Type the character 'b' in 1 second.
33 * - Move the pointer counterclockwise to 'z' in 2 seconds.
34 * - Type the character 'z' in 1 second.
35 * - Move the pointer clockwise to 'a' in 1 second.
36 * - Type the character 'a' in 1 second.
37 *
38 * Example 3:
39 *
40 * Input: word = "zjpc"
41 * Output: 34
42 * Explanation:
43 * The characters are printed as follows:
44 * - Move the pointer counterclockwise to 'z' in 1 second.
45 * - Type the character 'z' in 1 second.
46 * - Move the pointer clockwise to 'j' in 10 seconds.
47 * - Type the character 'j' in 1 second.
48 * - Move the pointer clockwise to 'p' in 6 seconds.
49 * - Type the character 'p' in 1 second.
50 * - Move the pointer counterclockwise to 'c' in 13 seconds.
51 * - Type the character 'c' in 1 second.
52 *
53 *
54 * Constraints:
55 *
56 * 1 <= word.length <= 100
57 * word consists of lowercase English letters.
58 *
59 */
60pub struct Solution {}
61
62// problem: https://leetcode.com/problems/minimum-time-to-type-word-using-special-typewriter/
63// discuss: https://leetcode.com/problems/minimum-time-to-type-word-using-special-typewriter/discuss/?currentPage=1&orderBy=most_votes&query=
64
65// submission codes start here
66
67impl Solution {
68 pub fn min_time_to_type(word: String) -> i32 {
69 0
70 }
71}
72
73// submission codes end
74
75#[cfg(test)]
76mod tests {
77 use super::*;
78
79 #[test]
80 fn test_1974() {
81 }
82}
83
Back
© 2025 bowen.ge All Rights Reserved.