13 September 2026 · Advanced track
Warehouse Load Balancing Triplets
Count how many distinct triplets of crate weights add up to a target load.
A loading dock has a list of crate weights waiting to be grouped into three-crate pallets, and a target pallet weight. Consider every way of choosing three different positions in the list, regardless of order. A group matches whenever the three weights at those positions add up to exactly the target. Return the total number of matching groups. Two matching groups that select the exact same three weight values only count as one - report the number of distinct weight-value combinations that match, not the number of different positions that could produce them.
Constraints
weights has between 0 and 500 entrieseach weight is a whole number between -1000000 and 1000000target is a whole number between -3000000 and 3000000a group must use three different positions from the list
Function signature
def count_target_sum_triplets(weights, target):