FastPrepMinimum Steps on a Circular Letter Dial

Minimum Steps on a Circular Letter Dial

IBM logoIBM● EasyINTERNOA
Learn

Problem 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) → int

Examples

Example 1

inputStr = "BZA"return = 4

Move 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

  • inputStr contains only uppercase English letters from A through Z.

More IBM problems

See IBM hiring insights
public int calculateMinSteps(String inputStr) {
  // Write your code here
}
inputStr"BZA"
expected4
Checking account…