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.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.
word='aaa' → 3
The pointer is already on a and never moves: three seconds for three key presses.
word='an' → 15
n is 13 steps away either way: 1 + 13 + 1 = 15.
word consists of lowercase English lettersword='bay'
7
Run checks the first 3 tests in your browser. Submit checks all 130 tests on the server, hidden ones included.