Easy20 pts
Beautiful Triplets
Count beautiful triplets: three indices i < j < k where arr[j] - arr[i] = d and arr[k] - arr[j] = d. The array is strictly increasing. Example: arr=[1,2,4,5,7,8,10], d=3 → Triplets: (1,4,7) with values (1,4,7), (2,5,8) with values (2,5,8), (4,7,10) with values (4,7,10) → Answer: 3
Input
First line: n d (space-separated). Second line: n space-separated integers (the array).
Output
A single integer: the count of beautiful triplets.
Sample
7 3 1 2 4 5 7 8 10
Expected
3
Loading editor…
Output
No output yet. Run your code to see results.