We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

Here's my Python code that passed all t he test cases:

importcollectionsdefsolve(a):# if every int appears only once in the list, then return 0iflen(a)==len(set(a)):return0else:# create a dict where the keys are elements of list 'a' # and the values are frequencies of the elements of 'a'ctr_dict=collections.Counter(a)total_pairs=0forxinctr_dict.values():# if an integer appears 'n' times, # there are n*(n-1) distinct pairs of indices (i,j)total_pairs+=x*(x-1)returntotal_pairs

## Sherlock and Pairs

You are viewing a single comment's thread. Return to all comments →

Here's my Python code that passed all t he test cases: