Count Triplets

  • + 1 comment
    def countTriplets(arr, r):
        count = 0
        elements = set(arr)
        for i in elements:
            first = i
            second = i*r
            third = i*r*r
            if (second in elements) and (third in elements):
                count += arr.count(first) * arr.count(second) * arr.count(third)
        return count
    

    i am facing an errorwhen r = 1. could someone please help me with it