Tool Changer
Reported by candidates from IBM's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The IBM Tool Changer question, reported in September 2026, looks like a story problem but it's a one-pass array scan. You've got a circular list of tool names, a start index, and a target string. Find the fewest moves to land on any copy of the target. The input is tiny, n is at most 100, so nothing here needs cleverness or heavy optimization. The risk is overthinking it or fumbling the wraparound. If you freeze on the OA, StealthCoder runs invisibly as a safety net. Most people won't need it for this one.
The problem
A milling machine has a circular tool changer containing n tools. A tool name may appear more than once. The operator can move through the changer one position at a time, either left or right. The changer is circular, so moving past one end wraps around to the other end. You are given: tools, the tool names in circular order; startIndex, the index of the tool currently in use; and target, the required tool name. Return the minimum number of one-position moves needed to reach any occurrence of target from startIndex. Function toolchanger(tools: String[], startIndex: int, target: String) → int Examples Example 1 tools = ["ballendmill", "keywaycutter", "slotdrill", "facemill"] startIndex = 1 target = "ballendmill" return = 1 The current tool is keywaycutter at index 1. The target ballendmill is at index 0. Moving left takes 1 step, while moving right takes 3 steps, so the answer is 1. Example 2 tools = ["ballendmill", "facemill", "keywaycutter", "slotdrill"] startIndex = 1 target = "slotdrill" return = 2 The current tool is facemill at index 1. The target slotdrill is at index 3. Moving left or right takes 2 steps, so the answer is 2. Constraints 1 <= tools.length <= 100 0 <= startIndex < tools.length 1 <= tools[i].length, target.length <= 100 target appears at least once in tools.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is circular distance. For every index i where tools[i] equals target, compute d = abs(i - startIndex). The shortest path is min(d, n - d), since you can go left or right around the ring. Take the minimum over all matches. That's O(n) time and O(1) space. With n capped at 100 you could even simulate stepping both directions, but the formula is cleaner. The common pitfalls are stopping at the first match, which is wrong because a later copy can be closer by wrapping, and forgetting the n - d branch. Also compare strings with equality, not reference checks, in languages like Java. If startIndex already holds the target, the answer is 0, and the formula handles that. If you blank on the wraparound math during the live OA, StealthCoder can surface the min(d, n - d) approach for you in real time.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Tool Changer cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass IBM's OA.
IBM reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Tool Changer FAQ
How hard is the IBM Tool Changer problem really?+
Easy. It's a single loop over an array with a circular distance formula. The constraints are small, n up to 100, so performance isn't a concern. Most of the difficulty is remembering that duplicates exist and that wraparound can make a later match closer.
What's the trick to Tool Changer?+
Use min(d, n - d) where d is the absolute difference between a matching index and startIndex. Do that for every occurrence of the target and keep the smallest result. That covers both directions around the circle without any simulation.
Do I need to handle the case where the start tool is already the target?+
Yes, but the formula covers it. If tools[startIndex] equals target, d is 0 and min(0, n) is 0. Don't add special casing unless it makes you more comfortable. Just make sure you scan all indices, not skip the start.
Can I just stop at the first match I find?+
No. Duplicate tool names are allowed, so the nearest copy might be later in the array but closer by wrapping around. Scan every index, compute the circular distance for each match, and track the minimum.
How should I prepare for this in 48 hours?+
Practice circular array distance and simple scans with min tracking. Write the function once from memory, test it on both examples and on a single-element array. This type of problem is about clean, bug-free code, so check edge cases like n = 1 and duplicates.