Subset sum easy doubt


getting run time error
please check my code , where i am missing

Hello @sk3657860,

Your Code is facing three different mistakes:

  1. 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;

  2. Wrong Output:
    reason:
    the output format of your code is wrong.
    Solution:
    Change β€œYES” and β€œNO” to β€œYes” and β€œNo” resp.

  3. 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.

1 Like

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.

1 Like

ooh
thank you!:smiley:

Anytime @sk3657860,

Please, mark this doubt as resolved.

1 Like