Class Solution
java.lang.Object
g1901_2000.s1974_minimum_time_to_type_word_using_special_typewriter.Solution
1974 - Minimum Time to Type Word Using Special Typewriter.<p>Easy</p>
<p>There is a special typewriter with lowercase English letters <code>'a'</code> to <code>'z'</code> arranged in a <strong>circle</strong> with a <strong>pointer</strong>. A character can <strong>only</strong> be typed if the pointer is pointing to that character. The pointer is <strong>initially</strong> pointing to the character <code>'a'</code>.</p>
<p><img src="https://assets.leetcode.com/uploads/2021/07/31/chart.jpg" alt="" /></p>
<p>Each second, you may perform one of the following operations:</p>
<ul>
<li>Move the pointer one character <strong>counterclockwise</strong> or <strong>clockwise</strong>.</li>
<li>Type the character the pointer is <strong>currently</strong> on.</li>
</ul>
<p>Given a string <code>word</code>, return the <strong>minimum</strong> number of seconds to type out the characters in <code>word</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> word = “abc”</p>
<p><strong>Output:</strong> 5</p>
<p><strong>Explanation:</strong></p>
<p>The characters are printed as follows:</p>
<ul>
<li>
<p>Type the character ‘a’ in 1 second since the pointer is initially on ‘a’.</p>
</li>
<li>
<p>Move the pointer clockwise to ‘b’ in 1 second.</p>
</li>
<li>
<p>Type the character ‘b’ in 1 second.</p>
</li>
<li>
<p>Move the pointer clockwise to ‘c’ in 1 second.</p>
</li>
<li>
<p>Type the character ‘c’ in 1 second.</p>
</li>
</ul>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> word = “bza”</p>
<p><strong>Output:</strong> 7</p>
<p><strong>Explanation:</strong></p>
<p>The characters are printed as follows:</p>
<ul>
<li>
<p>Move the pointer clockwise to ‘b’ in 1 second.</p>
</li>
<li>
<p>Type the character ‘b’ in 1 second.</p>
</li>
<li>
<p>Move the pointer counterclockwise to ‘z’ in 2 seconds.</p>
</li>
<li>
<p>Type the character ‘z’ in 1 second.</p>
</li>
<li>
<p>Move the pointer clockwise to ‘a’ in 1 second.</p>
</li>
<li>
<p>Type the character ‘a’ in 1 second.</p>
</li>
</ul>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> word = “zjpc”</p>
<p><strong>Output:</strong> 34</p>
<p><strong>Explanation:</strong></p>
<p>The characters are printed as follows:</p>
<ul>
<li>
<p>Move the pointer counterclockwise to ‘z’ in 1 second.</p>
</li>
<li>
<p>Type the character ‘z’ in 1 second.</p>
</li>
<li>
<p>Move the pointer clockwise to ‘j’ in 10 seconds.</p>
</li>
<li>
<p>Type the character ‘j’ in 1 second.</p>
</li>
<li>
<p>Move the pointer clockwise to ‘p’ in 6 seconds.</p>
</li>
<li>
<p>Type the character ‘p’ in 1 second.</p>
</li>
<li>
<p>Move the pointer counterclockwise to ‘c’ in 13 seconds.</p>
</li>
<li>
<p>Type the character ‘c’ in 1 second.</p>
</li>
</ul>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= word.length <= 100</code></li>
<li><code>word</code> consists of lowercase English letters.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minTimeToType
-