Trains the technique from
LeetCode 1848Minimum Distance to the Target ElementThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A single aisle of a stockroom holds bins side by side. labels[i] is the part number sitting in bin i, and a part number may appear in several bins. A picker is standing in front of bin start and needs the part numbered target.
Walking from bin i to bin j costs |i - j| paces. Return the smallest number of paces the picker must walk to stand in front of a bin holding target. The aisle is guaranteed to hold target in at least one bin.
Example 1
Bins 1 and 3 both hold part 2 and the picker stands at bin 2, so either one is a single pace away.
Example 2
Part 42 sits only in bin 4 and the picker stands at bin 0, so the walk is four paces.
Example 3
Part 5 sits in bins 1 and 3 while the picker stands at bin 4, so bin 3 is one pace away.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def nearest_matching_bin(labels: list[int], target: int, start: int) -> int:public int nearestMatchingBin(int[] labels, int target, int start)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.