Problem · String
Minimum Steps on a Circular Letter Dial
Learn this problemProblem statement
The uppercase English letters A through Z are arranged in a circle, so A and Z are adjacent.
A pointer starts at A. You may move it clockwise or counterclockwise, and each move to an adjacent letter costs exactly one step.
Given an uppercase string inputStr, visit its characters in order. Return the minimum total number of steps required.
Function
calculateMinSteps(inputStr: String) → intExamples
Example 1
inputStr = "BZA"return = 4Move from A to B in 1 step. The shortest route from B to Z is B → A → Z, which costs 2 steps. Finally, move from Z to A in 1 step. The total is 1 + 2 + 1 = 4.
Constraints
inputStrcontains only uppercase English letters fromAthroughZ.