You are viewing a single comment's thread. Return to all comments →
JavaScript solution:
function minimumDistances(a) { let minimumDistance = a.length; for (let i = 0; i < a.length; i++) { const currentNumber = a[i]; const nextNumberIndex = a.indexOf(currentNumber, i + 1); if (nextNumberIndex !== -1) { const indicesBetween = nextNumberIndex - i; if (minimumDistance > indicesBetween) { minimumDistance = indicesBetween; } } } if (minimumDistance === a.length) { return -1; } return minimumDistance; }
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Distances
You are viewing a single comment's thread. Return to all comments →
JavaScript solution: