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.
Sherlock and Pairs
Sherlock and Pairs
+ 0 comments 1 line Python solution, 100%
return sum(i*(i-1) for _,i in Counter(a).items())
+ 0 comments in c++, remember to change the result variable in the main() function long long result = solve(a);
+ 1 comment from collections import Counter def solve(a): c = Counter(a) count = 0 for i in c.values(): count += i*(i-1) return count
+ 0 comments a python3 solution
from collections import Counter def solve(a): C = Counter(a) return sum(n*(n-1) for n in C.values())
+ 0 comments For those who are trying in Java 8, you will need to change the given method to work with
long
and notint
.You also need to change that in the main, that is automatically generated by Hacker Rank.
Load more conversations
Sort 132 Discussions, By:
Please Login in order to post a comment