The program to find all triplets with the given sum in the given array is discussed here. Given an array of integers and a sum value, we need to iterate through the array and find all possible triplets that sum to the given value.
For example,
Consider the array: arr[] = {0, -1, 2, -3, 1}. The given sum is -2. In the given array, the triplets with sum = -2 are {0, -3, 1} and {-1, 2, -3}.
Time complexity: O(n^3)
@@coding::1@@
The triplets can be printed using the sorting technique.
Time complexity: O(n^2)
@@coding::2@@
Triplets can be found using the hashing technique.
Time complexity: O(n^2)
@@coding::3@@
Recommended Programs