https://ide.codingblocks.com/s/249888 This is my implementation anyone can u please correct it i produces all the subsequences which get the sum of target value
Need Some Help in the CODE
hi @akash.91.yadav you are producing correct output, but some values are repeating, so you need to change your approach a little.
- Sort the array(non-decreasing).
- First remove all the duplicates from array.
- Then use recursion and backtracking to solve the problem.
- If at any time sub-problem sum == 0 then add that array to the result (vector of vectors).
- Else if sum if negative then ignore that sub-problem.
- Else insert the present array in that index to the current vector and call the function with sum = sum-ar[index] and index = index, then pop that element from current index (backtrack) and call the function with sum = sum and index = index+1
Implementation
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.