Module 15 · Two Pointers

Triplets with a smaller sum

Sort the array and fix the smallest number of a triplet. If it, left and right add up to less than sum, so does left with every number between left and right (they're smaller than right): count them all at once and move left up. Otherwise the sum is too big, so right moves down.