• + 0 comments

    My python code (only runs last for loop if needed):

    def beautifulTriplets(d, arr):
        ans = 0
        for a in range(len(arr)):
            for b in range(a + 1, len(arr)):
                if arr[b] - arr[a] == d:
                    for c in range(b + 1, len(arr)):
                        if arr[c] - arr[b] == d:
                            ans += 1
        return ans