• + 1 comment

    for Python3 Platform

    def minimumDistances(a):
        min_d = 10000
        
        for i in range(len(a)-1):
            for j in range(i+1, len(a)):
                if (a[i] == a[j]):
                    min_d = min(min_d, abs(i-j))
        
        return -1 if min_d == 10000 else min_d
    
    n = int(input())
    a = list(map(int, input().split()))
    
    result = minimumDistances(a)
    
    print(result)