Triplet Sum

Published by Tjlhut in

Create a function that takes an unsorted list of numbers and returns the number of unique triplets whose sum is equal to the variable n.

Examples

triplet_sum([1, 0, 2, 6, 3, 9, 3], n = 11) ➞ 2
# Since we found two unique triplets that equate to 11: 0+2+9 and 2+6+3

triplet_sum([1, 2, 6, 3, 4, 5, 9, 10, 11], n = 20) ➞ 5

triplet_sum([5, 2, 8], n = 2) ➞ 0

Notes

You should also expect lists with less than three elements.

Watch a quick demo on how Edabit works.