Grokking LinkedIn Coding Interview
Ask Author
Back to course home

0% completed

Solution: Minimum Time to Type Word Using Special Typewriter

Problem Statement

You are given a circular keyboard that has all the lowercase English letters ('a' to 'z') laid out in a circle. You can type a particular character if the point is pointed to that character. Initially, a cursor points at the letter 'a'.

At each second, you can perform the following operation:

  • Move the cursor either one step to the left or right.
  • Type the letter where the pointer points currently.

Given a string word, return the minimum number of seconds to type out the characters in a word.

Examples

  • Example 1:
    • Input: "bad"

.....

.....

.....

Like the course? Get enrolled and start learning!