getting run time error
please check my code , where i am missing
Subset sum easy doubt
Hello @sk3657860,
Your Code is facing three different mistakes:
-
run-error
Reason:
i is going out of range. (print the value of i inside the function to see this)
Solution:
if(i>size && i<0)
return; -
Wrong Output:
reason:
the output format of your code is wrong.
Solution:
Change βYESβ and βNOβ to βYesβ and βNoβ resp. -
Even the logic you have applied if wrong.
1
3
1 2 -4
Expected Output:
No
Your Output:
Yes
Modified Code:
Hope, this would help.
Give a like if you are satisfied.
that part i got it
but i want to count the total no. of subset whose sum is 0
please help me with the my previous code that i have posted .
Sure @sk3657860,
You have done a silly mistake that was leading to all the previously mentioned errors i.e. out of bound and TLE.
You have swapped the position of i and sum in both the recursive calls that was leading your code to undefined output.
I have corrected your code:
Hope, this would help.
Give a like if you are satisfied.
ooh
thank you!