Didn't get the answer

Doubt 1:
when I comment out line 10, The last combination{2,7,1,5 : sum=15} that it gives is correct but when I sort it, the last combination is wrong {1,2,5,6 : sum=14}

what issue does it have with sort function?

doubt 2:
what is the way forward now?

Hey @prateek_5
This is happening because
say array is
5 1 1 and target sum is 6
now
we do take 5 take 1 skip 1 and sort and print 1 5
now we go back but op array is still sorted because passed by reference so next time we overwrite op array it overwrites 5 andmake it 1 1
I hope you got it know.

Regarding 2nd doubt
You can make a copy then sort it and print

1 Like

damn :open_mouth:
Thank you. let me try another part.

1 Like

hey @Kartikkhariwal1, Kindly look at my solution (Accepted :slight_smile: ).
Is it a good approach?

Hey @prateek_5
Yup this is fine.
You can also sort the input array in main before calling solve and it will always give you sorted subset at last.

1 Like

okay, will try this way.