You are viewing a single comment's thread. Return to all comments →
Is there a more optimised solution
def minimumDistances(a): count = dict(Counter(a)) d = [] for k,v in count.items(): if v>1: d.append(k) if(d==[]): return -1 else: zz = [] ret_distance = len(a) for x in d: zz.append([ i==x for i in a]) flag = True for i in range(len(zz)): c_index = -1 for j in range(len(zz[i])): if zz[i][j]==True: if(c_index < 0): c_index = j else: if (j-c_index)<ret_distance: ret_distance = j-c_index c_index = j return(ret_distance)
Minimum Distances
You are viewing a single comment's thread. Return to all comments →
Is there a more optimised solution