values, a number target and a zero-based index start. The target is guaranteed to appear in the array at least once.
Among all positions i with values[i] == target, pick the one closest to start and return the distance to it, that is |i - start|.values=[4, 7, 2, 7, 9, 4], target=4, start=3 → 2
The value 4 sits at positions 0 and 5. From position 3 they are 3 and 2 steps away, so position 5 is closer.
values=[8, 3, 8], target=8, start=0 → 0
The target is right at the starting position, so the distance is 0.
values.length ≤ 1000values[i] ≤ 10⁴start < values.lengthtarget occurs in valuesvalues=[4, 7, 2, 7, 9, 4], target=4, start=3
2
Run checks the first 3 tests in your browser. Submit checks all 119 tests on the server, hidden ones included.