Trains the technique from
LeetCode 9233Sum With MultiplicityThis 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 depot belt has weighed every parcel in a batch, giving loads, where loads[i] is the weight of the parcel at position i in kilograms.
A dispatcher wants to know how many ways three parcels can be pulled off the belt so their weights add up to exactly target kilograms. Count triples of positions (i, j, k) with i < j < k and loads[i] + loads[j] + loads[k] == target. Two triples are different when the positions differ, even if the three weights are identical.
The count can be enormous, so return it modulo 1000000007.
Example 1
Positions (0, 2, 3) weigh 2, 5 and 3, which add to 10, and positions (1, 2, 3) weigh the same three amounts. No other choice of three positions adds to 10.
Example 2
Any three of the four parcels weighing 50 kg add to 150 kg, which is four triples. Taking the 0 kg parcel, the 100 kg parcel and one of the four 50 kg parcels also adds to 150 kg, which is four more.
Example 3
There is only one choice of three positions on this belt, and 4 + 5 + 6 is 15, so it qualifies.
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 count_weight_triples(loads: list[int], target: int) -> int:public int countWeightTriples(int[] loads, int target)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.