#1534
Count Good Triplets
newbie · 190 · lc easy +16 · verified · 85.5% accepted · 1,203 likes · top 97%
Description
Given an integer array arr and thresholds a, b, c, a triplet (arr[i], arr[j], arr[k]) with i < j < k is good if all three pairwise absolute differences satisfy: |arr[i] - arr[j]| <= a, |arr[j] - arr[k]| <= b, and |arr[i] - arr[k]| <= c. Return the count of good triplets.
Example 1:
Input: arr = [3,0,1,1,9,7], a = 7, b = 2, c = 3
Output: 4
Explanation: 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.
Code
1
2
3