FastPrepMinimum Circular Tool Distance

Minimum Circular Tool Distance

JP Morgan Chase logoJP Morgan Chase● EasyINTERNOA

Updated

Problem statement

You are given a circular array of labels tools, a zero-based starting index start and a label target. One step moves to the next or previous array position. Moving past either end wraps around to the other end. Labels may repeat.

Return the fewest steps needed to reach any position whose label equals target. If you are already at a matching position, return 0. For this exercise, assume exact case-sensitive label comparison and return -1 when the target is absent. Integer labels may be supplied as their decimal text; no arithmetic is performed on labels.

Function

minimumToolSteps(tools: String[], start: int, target: String) → int

Examples

Example 1

tools = ["saw","hammer","mallet","file","saw","ladder","scissor"]start = 6target = "saw"return = 1

Moving one step right wraps from index 6 to index 0, whose label is saw. No move of length 0 reaches saw.

Example 2

tools = ["a","b","c"]start = 1target = "x"return = -1

No position has label x, so the target cannot be reached.

Constraints

  • 1 <= tools.length <= 1000
  • 1 <= tools[i].length, target.length <= 30
  • 0 <= start < tools.length
  • Every label contains only printable ASCII characters from code 33 through 126, with no spaces.

More JP Morgan Chase Online Assessment questions

Similar questions at other companies

Interview reports that mention this question

JP Morgan Chase interview experiences

All JP Morgan Chase interview questionsSee JP Morgan Chase hiring insights
Saved
class Solution {
    public int minimumToolSteps(String[] tools, int start, String target) {
        // Write your code here.
    }
}
Checking account…