Trains the technique from
LeetCode 3741Minimum Distance Between Three Equal Elements IIThis 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.
Readings are given as nums.
Find three positions holding the same reading and return the span from the first of them to the last, which is the difference of those two positions. Return -1 when no reading appears three times.
Example 1
The reading 2 sits at positions 1, 5, 6 and 9; the triple at 5, 6 and 9 spans 4, and the one at 1, 5 and 6 spans 5. The reading 4 sits at 0, 2 and 4, spanning 4, and the reading 7 at 3, 7 and 8, spanning 5. The tightest is 4.
Example 2
The only triple runs from position 0 to position 2.
Example 3
No reading appears even twice, let alone three times.
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 minimum_distance(nums: list[int]) -> int:public int minimumDistance(int[] nums)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.