Subset sum easy(what to do)

Hey @Saksham12,

There are multiple issues in your code:

  1. The base condition is incorrect.
    The statements after base condition will never execute.
    Reason:
    You have use if and else control.
    So, either statements in if will execute or in else block and both have return statement.
    This will terminate the function.

  2. There is no return statement for recursive statements.

  3. The output format is incorrect.
    The output of each test case should be in a different line.

  4. You are using char array.
    How would this store -123 or 235454?

I have corrected everything:

But, this will still produce the wrong output:
Reason:
As you are passing sum as 0, initially.
So, it will be true for sure for the case when you would add no element to sum.
Example:
2
1 2 3 4
Solution:
Pass sum as junk value.

Correct Code:

Hope, this would help.
Give a like if you are satisfied.

1 Like

Thanks for the corrections you made, I was unable to perform some questions on recursion that’s why I left this question , I will get it resolved by tomorrow