You are viewing a single comment's thread. Return to all comments →
Solution on Python3
from collections import Counter n = int(input()) elements = list(map(int, input().split(' '))) print("-1" if len(set(elements)) == n else "", end="") if len(set(elements)) != n: repeated_list = [_ for _ in Counter(elements) if Counter(elements).get(_) > 1] less_distance = [] for i in repeated_list: indices = [index for index, j in enumerate(elements) if j == i] less_distance.append(abs(indices[0] - indices[1])) print(min(less_distance))
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 →
Solution on Python3