Sum it up-Recursion, How to not print duplicate answers?

Hi, for the question sum it up, my code is printing duplicate queries, how do I avoid that?

Hey just add a return statement inside the first if condition and it works. Since once you have reached t==0, you do not need to try any further combinations unnecessarily.

1 Like

Also it says print the answers in a lexicographical order, so its better to store them in vectors of vectors and then sort them and print to get a lexicographical order.

1 Like

That worked, silly mistake on my part. Thank you!

Sir could you please tell edit my code and show to implement that?