Easy20 pts
Minimum Distances
Find the minimum distance between any two equal elements. Distance = absolute difference of their indices. If all elements are unique, return -1. Example: a=[7,1,3,4,1,7] → Element 1 at indices 1 and 4 → distance=3. Element 7 at indices 0 and 5 → distance=5. Minimum is 3.
Input
First line: n. Second line: n space-separated integers.
Output
A single integer: the minimum distance, or -1 if all elements are unique.
Sample
6 7 1 3 4 1 7
Expected
3
Loading editor…
Output
No output yet. Run your code to see results.