set08

Find three discount codes that sum to a total

8 / 26
read the snippet · pick its Big-O
// Brute-force search for any 3 promo codes whose values sum to "target".
function findTriple(codes, target) {
for (let i = 0; i < codes.length; i++)
for (let j = 0; j < codes.length; j++)
for (let k = 0; k < codes.length; k++)
if (codes[i] + codes[j] + codes[k] === target) return [i, j, k];
return null;
}