Minimum Circular Tool Distance
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) → intExamples
Example 1
tools = ["saw","hammer","mallet","file","saw","ladder","scissor"]start = 6target = "saw"return = 1Moving 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 = -1No position has label x, so the target cannot be reached.
Constraints
1 <= tools.length <= 10001 <= tools[i].length, target.length <= 300 <= 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
- Find Total CostOA · Seen Oct 2026
- Minimum Meeting RoomsOA · Seen Oct 2026
- Count Dropped RequestsOA · Seen Oct 2026
- Maximize Minimum Deployment DifficultyOA · Seen Oct 2026
- Task SchedulingOA · Seen Oct 2026
- Substring RemovalOA · Seen Oct 2026
- Maximum Game Board ScoreOA · Seen Sep 2026
- Minimum Digit Changes Between String HalvesOA · Seen Sep 2026
- Same Substring Within BudgetOA · Seen Sep 2026
- Invert Ad Visibility BitsOA · Seen Aug 2026
Similar questions at other companies
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
- Count Multiples of Three with Two SevensHudson River Trading · OAHudson River Trading interview questions
- Customer Signer ScreeningState Farm · OA
- REST API: Highest International StudentsRippling · OARippling interview questions
- String-Pair Frequency SimilarityIBM · OAIBM interview questions
- Find Sliding-Window Pattern Start IndicesVisa · OAVisa interview questions
- Closest ColorTwo Sigma · OATwo Sigma interview questions
- Number-Character Bijective MappingAdobe · OAAdobe interview questions