Given an array of unique numbers and a value, a valid triplet is a set of three numbers (not necessarily continuous in the array) that add up to the value. Write a program to count all valid triplets. Print the number of valid triplets.
Hint: Can you solve this in O(n^2) steps?
Input : First line contains N and Sum (Space separated). Second line contains space separated list of N numbers.
Output: Number of triplets such that sum possible
Constraints:
- 0 < N < 100
- All numbers in the list are unique and between -10^4 to 10^4
- -10^3 < Sum < 10^3
Solution -: