Trains the technique from
LeetCode 2964Number of Divisible Triplet SumsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A monitoring rig stores one reading per channel in the array nums, and a reporting tool batches readings into groups whose total has to divide evenly among d shifts.
Count the position triples (i, j, k) with i < j < k for which nums[i] + nums[j] + nums[k] is a multiple of d. Two triples are the same triple when they use the same three positions, so each set of three positions is counted once even if the readings there are equal.
Return that count.
Example 1
Three position triples qualify: (0, 1, 2) totals 20, (0, 1, 5) totals 25 and (2, 4, 5) totals 25, and each of those is a multiple of 5.
Example 2
Every triple of positions totals 6, which is a multiple of 3, and there are 4 ways to choose three of the four positions.
Example 3
Fewer than three readings exist, so no triple can be formed.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def divisible_triplet_count(nums: list[int], d: int) -> int:public int divisibleTripletCount(int[] nums, int d)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.