Given an array of integers, find three integers in the array that sum to a specific target number.
Input = [12, 3, 1, 2, -6, 5, -8, 6];
Target = 0
Output: [ [ -8, 2, 6 ], [ -8, 3, 5 ], [ -6, 1, 5 ] ]
All the triplets when added, result in a sum of 0 - which is the target sum.
-1000 <= Input <= 1000
-1000 <= Target <= 1000
Click to reveal
Can you do this in a brute force way first with the help of loops? This will not be the most optimal solution but you can get an idea of how to proceed from here.
Sort the array and you might get a way to iterate over it in a meaningful way.