Count the number of index triplets whose pairwise absolute differences stay within given bounds.
Given an array of integers nums and three integers a, b, and c, count how many triplets of indices (i, j, k) satisfy:
0 <= i < j < k < nums.length|nums[i] - nums[j]| <= a|nums[j] - nums[k]| <= b|nums[i] - nums[k]| <= cReturn the total number of such good triplets.
This is a straightforward counting problem: you need to examine ordered index triplets and test whether they meet all three value-difference constraints.
numsa, b, and c3 <= nums.lengtha, b, and c are non-negative integersExample 1
Input
nums = [3,0,1,1,9,7], a = 7, b = 2, c = 3
Output
4
Explanation
The good triplets are indexed by (0,1,2), (0,1,3), (0,2,3), and (1,2,3).
Example 2
Input
nums = [1,1,2,2,3], a = 0, b = 0, c = 1
Output
0
Explanation
No ordered triplet of indices satisfies all three difference constraints.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.