Minimum Steps on a Circular Character Dial
Problem statement
You are given a circular array of characters as ring, a starting index startIndex, and a target string. Moving clockwise or counterclockwise to an adjacent ring position costs one step.
For this exercise, assume you must visit the target characters in order. Visiting a character costs no extra selection step. The ring may contain duplicate characters, and you may choose any occurrence when visiting the next target character. Return the minimum total movement cost, or -1 if a target character is absent. An empty target costs zero steps.
Function
calculateMinSteps(ring: String, startIndex: int, target: String) → intExamples
Example 1
ring = "ABCDEF"startIndex = 2target = "FA"return = 4From C at index 2, reach F in three moves in either direction, then A in one move. The total is four.
Example 2
ring = "ABACA"startIndex = 1target = "AC"return = 2Choose A at index 2, one step from B, then C at index 3 in one more step. Choosing A at index 0 would cost more before the following C.
Example 3
ring = "XYZ"startIndex = 2target = "A"return = -1A does not occur on the supplied ring.
Constraints
1 <= ring.length <= 100.0 <= startIndex < ring.length.0 <= target.length <= 100.- For this exercise, assume ring and target characters are ASCII letters and digits.