Trains the technique from
LeetCode 3761Minimum Absolute Distance Between Mirror PairsThis 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 rail holds tags in a row, and codes[i] is the positive whole number printed on the tag at position i.
The mirror of a number is what you read when its decimal digits are read back to front, with any leading zeros the reversal produces thrown away. The mirror of 47 is 74, the mirror of 1200 is 21, and the mirror of 66 is 66.
Two positions i and j with i < j form a mirror pair when at least one of the two printed numbers is the mirror of the other, and the gap of that pair is j - i.
Return the smallest gap over all mirror pairs on the rail. Every gap is at least 1, so return -1 when the rail holds no mirror pair at all.
Example 1
Position 0 prints 13 and position 3 prints 31, which is the mirror of 13, so that pair has gap 3 and no other pair on the rail forms a mirror pair.
Example 2
Position 4 prints 21 and position 5 prints 120, whose mirror is 21, so that pair has gap 1.
Example 3
The mirrors of 10, 20 and 30 are 1, 2 and 3, none of which is printed on the rail, so no pair qualifies.
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 closest_mirror_tag(codes: list[int]) -> int:public int closestMirrorTag(int[] codes)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.