Beautiful Triplets
easy⏱ 15 mintypescriptchallengesproblem-solving-basic-
Sample case — your program reads stdin and prints to stdout.
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 format
First line: n d (space-separated). Second line: n space-separated integers (the array).
Output format
A single integer: the count of beautiful triplets.
Constraints
1 ≤ n ≤ 10⁴, 1 ≤ d ≤ 20, 0 ≤ arr[i] ≤ 2×10⁴