java.lang.Object
g1901_2000.s1974_minimum_time_to_type_word_using_special_typewriter.Solution

public class Solution extends Object
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 = &ldquo;abc&rdquo;</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 &lsquo;a&rsquo; in 1 second since the pointer is initially on &lsquo;a&rsquo;.</p> </li> <li> <p>Move the pointer clockwise to &lsquo;b&rsquo; in 1 second.</p> </li> <li> <p>Type the character &lsquo;b&rsquo; in 1 second.</p> </li> <li> <p>Move the pointer clockwise to &lsquo;c&rsquo; in 1 second.</p> </li> <li> <p>Type the character &lsquo;c&rsquo; in 1 second.</p> </li> </ul> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> word = &ldquo;bza&rdquo;</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 &lsquo;b&rsquo; in 1 second.</p> </li> <li> <p>Type the character &lsquo;b&rsquo; in 1 second.</p> </li> <li> <p>Move the pointer counterclockwise to &lsquo;z&rsquo; in 2 seconds.</p> </li> <li> <p>Type the character &lsquo;z&rsquo; in 1 second.</p> </li> <li> <p>Move the pointer clockwise to &lsquo;a&rsquo; in 1 second.</p> </li> <li> <p>Type the character &lsquo;a&rsquo; in 1 second.</p> </li> </ul> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> word = &ldquo;zjpc&rdquo;</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 &lsquo;z&rsquo; in 1 second.</p> </li> <li> <p>Type the character &lsquo;z&rsquo; in 1 second.</p> </li> <li> <p>Move the pointer clockwise to &lsquo;j&rsquo; in 10 seconds.</p> </li> <li> <p>Type the character &lsquo;j&rsquo; in 1 second.</p> </li> <li> <p>Move the pointer clockwise to &lsquo;p&rsquo; in 6 seconds.</p> </li> <li> <p>Type the character &lsquo;p&rsquo; in 1 second.</p> </li> <li> <p>Move the pointer counterclockwise to &lsquo;c&rsquo; in 13 seconds.</p> </li> <li> <p>Type the character &lsquo;c&rsquo; 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 Details

    • Solution

      public Solution()
  • Method Details

    • minTimeToType

      public int minTimeToType(String word)