#C3761. Beautiful Triplets
Beautiful Triplets
Beautiful Triplets
Given an array of n integers and an integer d, your task is to count the number of beautiful triplets in the array. A triplet (i, j, k) such that i < j < k is called a beautiful triplet if it satisfies the following conditions:
$$a_j - a_i = d$$
$$a_k - a_j = d$$
Where \(a_i, a_j, a_k\) are the elements of the array at indices \(i, j, k\) respectively. Your goal is to compute the total number of such triplets.
Example:
Input: n = 7, d = 3, arr = [1, 2, 4, 5, 7, 8, 10] Output: 3</p>Explanation: The beautiful triplets are (1,4,7), (2,5,8) and (4,7,10).
inputFormat
The input is given in the following format:
- The first line contains two space-separated integers n and d, where n is the number of elements in the array and d is the required difference.
- The second line contains n space-separated integers representing the elements of the array.
outputFormat
Output a single integer on a new line indicating the number of beautiful triplets found in the array.
## sample7 3
1 2 4 5 7 8 10
3
</p>