Given an array of integers arr, and three integers&nbsp;a,&nbsp;b&nbsp;and&nbsp;c. You need to find the number of good triplets.

A triplet (arr[i], arr[j], arr[k])&nbsp;is good if the following conditions are true:


	0 &lt;= i &lt; j &lt; k &lt;&nbsp;arr.length
	|arr[i] - arr[j]| &lt;= a
	|arr[j] - arr[k]| &lt;= b
	|arr[i] - arr[k]| &lt;= c


Where |x| denotes the absolute value of x.

Return the number of good triplets.

&nbsp;
Example 1:

Input: arr = [3,0,1,1,9,7], a = 7, b = 2, c = 3
Output: 4
Explanation:&nbsp;There are 4 good triplets: [(3,0,1), (3,0,1), (3,1,1), (0,1,1)].


Example 2:

Input: arr = [1,1,2,2,3], a = 0, b = 0, c = 1
Output: 0
Explanation: No triplet satisfies all conditions.


&nbsp;
Constraints:


	3 &lt;= arr.length &lt;= 100
	0 &lt;= arr[i] &lt;= 1000
	0 &lt;= a, b, c &lt;= 1000

class Solution:
    def countGoodTriplets(self, arr: List[int], a: int, b: int, c: int) -> int:
        count = 0
        for i in range(len(arr)):
            for j in range(i+1,len(arr)):
                for k in range(j+1,len(arr)):
                    if abs(arr[i]-arr[j])<=a and abs(arr[j]-arr[k])<=b and abs(arr[k]-arr[i])<=c:
                        count+=1
        return count
class Solution {
    public int countGoodTriplets(int[] arr, int a, int b, int c) {
        int total = 0;
        for (int i = 0; i < arr.length - 2; i++){
            for (int j = i+1; j < arr.length - 1; j++){
                for (int k = j+1; k < arr.length; k++){
                    if (helper(arr[i], arr[j]) <= a &&
                            helper(arr[j], arr[k]) <= b &&
                                helper(arr[k], arr[i]) <= c)
                        total++;
                }
            }
        }
        return total;
    }

    private static int helper(int x, int y) {
        return Math.abs(x - y);
    }
}
class Solution {
public:
    int countGoodTriplets(vector<int>& arr, int a, int b, int c) {
        int ct = 0;
        for(int i = 0; i<arr.size()-2; i++)
        {
            for(int j = i+1; j<arr.size()-1; j++)
            {
                if(abs(arr[i]-arr[j])<=a)
                    for(int k = j+1; k<arr.size(); k++)
                    {
                        if(abs(arr[j]-arr[k])<=b && abs(arr[i]-arr[k])<=c)
                            ct++;
                    }
            }
        }
        return ct;
        
    }
};
var countGoodTriplets = function(arr, a, b, c) {
  let triplets = 0;

  for (let i = 0; i < arr.length - 2; i++) {
    for (let j = i + 1; j < arr.length - 1; j++) {
      if (Math.abs(arr[i] - arr[j]) > a) continue;
      for (let k = j + 1; k < arr.length; k++) {
        if (Math.abs(arr[j] - arr[k]) > b || Math.abs(arr[i] - arr[k]) > c) {
          continue;
        }
        triplets++;
      }
    }
  }

  return triplets;
};
Count Good Triplets