Minimum Steps on a Circular Character Dial
Updated
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.
More Navan interview questions
- Time Based Key-Value StoreONSITE INTERVIEW · Seen Dec 2025
- Type-Ahead Prefix MatchesONSITE INTERVIEW · Seen Dec 2024
- Minimum Stick Connection CostONSITE INTERVIEW · Seen Jan 2024
- Shortest Substring with at Least K Distinct CharactersONSITE INTERVIEW · Seen Jan 2024
- Compare N-Ary Tree Leaf SequencesONSITE INTERVIEW · Seen Nov 2023
- Roman to IntegerPHONE SCREEN · Seen Oct 2024
- Sort ColorsPHONE SCREEN · Seen Oct 2024
- Basic CalculatorPHONE SCREEN · Seen Jun 2024
- LRU CachePHONE SCREEN · Seen Jun 2024
- House RobberPHONE SCREEN · Seen May 2024
Similar questions at other companies
- Maximum Bouquet ValueOracle · ONSITE INTERVIEWOracle interview questions
- Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Word BreakGoogle · ONSITE INTERVIEWGoogle interview questions
- Reconstruct One Sentence From a DictionaryMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Scramble StringExpedia · ONSITE INTERVIEWExpedia interview questions
- Word BreakMoveworks · ONSITE INTERVIEWMoveworks interview questions
- Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Decode Numeric StringArcesium · ONSITE INTERVIEWArcesium interview questions
- Word BreakBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Count Vowel PermutationsZscaler · ONSITE INTERVIEWZscaler interview questions