Count Good Triplets

PHOTO EMBED

Thu Oct 20 2022 09:56:13 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

class Solution {
public:
    int countGoodTriplets(vector<int>& arr, int a, int b, int c) {
         int ans=0;
        int n=arr.size();
        for(int i=0;i<n-2;i++)
        {
            for(int j=i+1;j<n-1;j++)
            {
                for(int k=j+1;k<n;k++)
                {                                                                                                       if(abs(arr[i]-arr[j])<=a && abs(arr[j]-arr[k])<=b && abs(arr[i]-arr[k])<=c)
                    {
                        ans++;
                    }
                }
            }
        }
        return ans;
    }
};
content_copyCOPY

https://leetcode.com/problems/count-good-triplets/