Optimal Alphabet Stepping Given an input string consisting of only letters, return the step-size that results in the minimum amount of steps that are needed to visit all the letters in order over a wrapping alphabet, starting at any letter.

For example, take the word, dog. If we use a step-size of 1, we end up with:

defghijklmnopqrstuvwxyzabcdefg   Alphabet
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
defghijklmnopqrstuvwxyzabcdefg   Visited letters
d          o                 g   Needed letters


For a total of 30 steps.

However, if we use a step-size of 11, we get:

defghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg
^          ^          ^          ^          ^          ^
d          o          z          k          v          g   Visited letters
d          o                                           g   Needed letters


For a total of 6 steps. This is the minimum amount of steps, so the return result for dog is the step-size; 11.

Test cases:

"dog"      -&gt; 11
"age"      -&gt; 6
"apple"    -&gt; 19
"alphabet" -&gt; 9
"aaaaaaa"  -&gt; 0 for 0 indexed, 26 for 1 indexed
"abcdefga" -&gt; 1 or 9
"aba"      -&gt; Any odd number except for 13
"ppcg"     -&gt; 15
"codegolf" -&gt; 15
"testcase" -&gt; 9
"z"        -&gt; Any number
"joking"   -&gt; 19


Rules


Input will be a non-empty string or array of characters consisting only of the letters a to z (you can choose between uppercase or lowercase)
Output can be 0 indexed (i.e. the range 0-25) or 1 indexed (1-26)
If there's a tie, you can output any step-size or all of them
This is code-golf, so the lowest amount of bytes for each language wins!
Charcoal, 41 bytes

≔ＥＥβＥθ∧μ⌕⭆β§β⁺⌕β§θ⊖μ×κξλ⎇⊕⌊ιΣι⌊ιθＩ⌕θ⌊Φθ⊕ι


Try it online! Link is to verbose version of code. 0-indexed. Explanation:

Ｅβ


Loop over the 26 step sizes. (Actually I loop over the lowercase alphabet here and use the index variable.)

Ｅθ∧μ


Loop over each character of the input after the first.

⭆β§β⁺⌕β§θ⊖μ×κξ


Loop 26 times and generate the string of characters resulting by taking 26 steps at the given step size starting (0-indexed) with the previous character of the input.

⌕...λ


Find the position of the current character of the input in that string, or -1 if not found.

Ｅ...⎇⊕⌊ιΣι⌊ι


Take the sum of all the positions, unless one was not found, in which case use -1.

≔...θ


Save the sums.

⌊Φθ⊕ι


Find the minimum non-negative sum.

Ｉ⌕θ...


Find the first step size with that sum and output it.