The 3-Sum problem is a classic algorithmic problem where the objective is to find all unique triplets in an array that sum up to a specific target value, usually zero. This problem is a popular interview question and is commonly used in coding challenges to test a candidate's understanding of arrays, sorting, and efficient algorithms.
The 3Sum problem can be divided into two categories based on whether the input array is sorted or unsorted.
3Sum on Unsorted Input
- All Triplets with Zero Sum
- All triplets with given sum
- Triplet Sum Closest to Given Sum
- Pythagorean Triplet
- All Pythagorean Triplets
- All Unique Triplets with Given Sum
- Triplets with Sum of 2 equal to 3rd
3Sum on Sorted Input
- 3 Sum – Triplet Sum in Array
- 3 Sum – All Distinct Triplets with given Sum in an Array
- 3 Sum – Triplet Sum Closest to Target
- Three closest elements from three sorted
- Triplet with given sum in BST
- Triplet in a Balanced BST with sum zero
- Count triplets with smaller sum