A milling machine in a manufacturing facility has a tool change system. The tool changer holds n tools and some duplicate tools may be included. The operator must move through the tools one at a time, either moving left or right. The tool changer is circular, so when the last tool in the tools array is reached in either direction, the next tool is at the other end of the array.
Given the name of the next tool needed, determine the minimum number of left or right moves to reach it.
Complete the function toolchanger in the editor.
toolchanger has the following parameter(s):
String[] tools: an array of tool names arranged in the order they appear in the tool changerint startIndex: index of the tool currently in useString target: name of the tool needed
Returns
int: the minimum number of moves
tools = ["ballendmill", "keywaycutter", "slotdrill", "facemill"] startIndex = 1 target = "ballendmill" return = 1
The tool currently in use is keywaycutter at index 1. The desired tool is ballendmill at index 0. It can be reached by moving right 3 steps or left 1 step. The minimum number of moves is 1.
🐕🦺🐕- Minimize Total Input Cost (for LTMS)Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Key Teams in TreeOA · Seen Mar 2026
- System Energy ReductionOA · Seen Mar 2026
- Update Logs by Symmetric XOROA · Seen Mar 2026
- Count Palindromic Concatenation PairsOA · Seen Mar 2026
- Collect Opportunity Data in a TreeOA · Seen Feb 2026
- Replace '?' to Avoid Adjacent DuplicatesOA · Seen Feb 2026
public int toolchanger(String[] tools, int startIndex, String target) {
// write your code here
}