Company: Publicis-Sapient_13thjuly
Difficulty: medium
You are given an array of integers and a number d . Select a group of three elements where the difference between the largest and smallest values in the group is at most d . Return the total number of such groups, modulo (10 9 + 7). Example 1 Input: arr = [-3, -2, -1, 0], d = 2 Output: 2 Explanation: All Valid Triplets Triplet Count Elements of the triplet Maximum Difference 1 [-3, -2, -1] (-1) - (-3) = 2 2 [-2, -1, 0] 0 - (-2) = 2 Example 2 Input: arr = [2, 1, 3, 4], d = 3 Output: 4 Explanation: All Valid Triplets Triplet Count Elements of the triplet Maximum Difference 1 [2, 1, 3] 3 - 1 = 2 2 [2, 1, 4] 4 - 1 = 3 3 [2, 3, 4] 4 - 2 = 2 4 [1, 3, 4] 4 - 1 = 3 Constraints 3 ≤ size of arr ≤ 2 * 10 ^5