words and two different words first and second, each appearing in the list at least once (possibly several times).
The distance between positions i and j is |i - j|. Return the smallest distance between any position holding first and any position holding second.words=['red', 'green', 'blue', 'red', 'yellow', 'blue'], first='red', second='blue' → 1
"red" is at positions 0 and 3, "blue" at 2 and 5. The closest pair is 3 and 2, one step apart.
words=['cat', 'dog', 'fox', 'owl'], first='owl', second='cat' → 3
Each word appears once, at positions 3 and 0, so the distance is 3.
len(words) ≤ 3 · 10⁴first and second both occur in wordsfirst ≠ secondwords=['red', 'green', 'blue', 'red', 'yellow', 'blue'], first='red', second='blue'
1
Run checks the first 3 tests in your browser. Submit checks all 99 tests on the server, hidden ones included.