Subset sum easy(what to do)
Hey @Saksham12,
There are multiple issues in your code:
-
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. -
There is no return statement for recursive statements.
-
The output format is incorrect.
The output of each test case should be in a different line. -
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.
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