Triplets with given Sum

Given an array, we need to find if there is a triplet in the array whose sum is equal to a given value. If such a triplet is present, we need to print it and return true. Else, return false.

Example -
Input: arr = [3,4,12,6,2,9] , sum = 24
Output: 3 , 12 , 9
Explanation: The triplet(3,9,12) give us a sum of 24.Method 1- Naive Approach

In this method, we will find all the possible triplets and compute their sum, till we get the desired sum.

We are given an array arr of length n and a sum s.W...
 •  0 comments  •  flag
Share on Twitter
Published on February 15, 2021 01:57
No comments have been added yet.