Count Triplets

  • + 0 comments

    can someone please help me understand the problem with my code??

    def countTriplets(arr, r):
        d = defaultdict(int)
        count = 0
        for i in arr:
            d[i] += 1
        for i in d:
            if i == i*r and i == i*r*r:
                count = count + (d[i] * (d[i]-1) * (d[i] - 2)) // 6
            else:
                if i*r in d and i*r*r in d:
                    count = count + d[i] * d[i*r] * d[i*r*r]
            
        return count