I am preparing for my Campus Placements. I came across a question, which goes like this:
Given 3 arrays, like
array 1: {2,1,4,7}
array 2: {3,-3,-8,0}
array 3: {-1,-4,-7,6}
We have to extract one number from each array and form triplets such that the sum of the numbers in the triplet is 0, or any number for that fact.
For example, for the above case, one of the solutions can be {2, -8, 6}
Currently, I have not been able to think of any solution other than the Brute Force method which will take O(n^3)
time. How to do this in lesser time?
Thanks in advance.