Sort by

recency

|

134 Discussions

|

  • + 0 comments

    for those who are getting wrong answer for cpp code multiply 1ll when adding to ans variable long long ans = 0; for(auto v : mp){ ans += 1ll * v.second * (v.second-1); }

  • + 0 comments

    For solution in c++ or other languages where size of the integer matters, you have to change the template. You need long long to count and return in C++.

  • + 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