Ctrl K

Typing on a Rotary Dial

Easy
The letters a to z are printed around a circular dial, with a following z again. A pointer sits over the dial and starts on a. You can only type the letter the pointer is currently on. Each second you perform exactly one action: - turn the pointer one letter clockwise or counterclockwise; - type the letter under the pointer. Given a word word, return the fewest seconds needed to type all of it.
Example 1
word='bay' → 7

1 second to reach b, 1 to type it; 1 back to a, 1 to type; from a to y the short way round takes 2 seconds, plus 1 to type. 7 in total.

Example 2
word='aaa' → 3

The pointer is already on a and never moves: three seconds for three key presses.

Example 3
word='an' → 15

n is 13 steps away either way: 1 + 13 + 1 = 15.

Constraints
  • 1 ≤ len(word) ≤ 100
  • word consists of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPalindrome From Letter Tiles EasyPalindrome With One Eraser Stroke EasyRise and Fall Lineup EasyMost Even L/R Pieces EasyTime Behind the Smudges Easy
loading Python…
Input
word='bay'
Expected
7

Run checks the first 3 tests in your browser. Submit checks all 130 tests on the server, hidden ones included.