sir i am getting repetitive pairs of triplets
how to discard them
Target sum triplet
just ignore the first element already taken in a triplet using this code
if your doubt is solved kindly mark it as resolved
the code is giving wrong output
sir in the code all the three nos should be different but in the output those combination is also coming in which 2 nos are same
sir its resolved but if we do i=b then two nos should always be equal but they are not why
sir my code is showing reuntime error please check it
hey, can you give me any test case where it is failing, i checked a few cases and it seems to work fine
nonetheless, 2 of the better approaches to this solution are as follows:
(1) run a loop for i:n store the ith element and calculate the remaining sum, in the array ahead of the ith element. take each element one by one from i+1th element to n till the i+1th element < remaining sum, subtract this element as well from the remaining
For both the approaches the steps till here remain the same
in (1) binary search for the rem while also maintaining that this element must occur at an index greater than i+1
(2) map based approach: just initially put all the elements in the map and check the presence of rem in the map while also maintaining that this element must occur at an index greater than i+1