SalesforceOA #42
Tool Changer
Estimated EasyJudge-ready
Topics (AI-labelled)In-place ArraysSimulation
Tool names are arranged in circular order, and duplicates are allowed. You start at startIndex, and each move goes one position left or right; find the minimum number of steps to reach any position holding the target name. Added by this site: output −1 if the target cannot be found. Names match only if they are exactly equal; case and whitespace must not be ignored.
Input
The input is a JSON array [tools,startIndex,target], with zero-based indices. The original has no numeric or character bounds; this site adds 1≤n≤100000, each name and target has length 0..16 Unicode scalar values, and empty names, whitespace, NUL, and non-BMP characters are allowed, but lone surrogates are not; 0≤startIndex<n. The entire JSON-encoded input is ≤20000000 bytes, so ASCII-escaped encoding can cover the complete worst-case name domain.
Output
Output one integer answer.
Example 1
Input:
[["ballendmill","keywaycutter","slotdrill","facemill"],1,"ballendmill"]
Output:
1
Example 2
Input:
[["","a",""],1,""]
Output:
1
Example 3
Input:
[["\ud83d\ude00","\u0000"],0,"absent"]
Output:
-1
Example notes
The outputs of the three public examples are, in order: 1; 1; -1. They have been checked by independent enumeration or direct simulation.
Editorial
Loading solution…