Programming Question: Leetcode-15
Approach to solve leetcode question-15 3Sum
We can get all combinations of 3 elements and see their sum is equal to 0 or not and return all combinations which sums to 0, but this approach will not be efficient.
Instead we will use following approach:
- we will sort the array first.
2. we will take each element of array and for elements after this , we will choose two elements , calculate sum of all elements and if it is 0 , add all elements in result array . It will be clear in code.