Subset sum easy

  1. as soon as sum becomes zero then return
  2. empty subset return sum zero
    how to handle these two cases ?

for 1) use the return type of your function as bool, so if sum==0 then return true.
for 2) use extra parameter with in the function, which will denote the number of element you have taken in the subset, so just modify you base condition like if(sum==0 && extra_parameter!=0) return true.

I hope you will be able to solve it now.
Please mark this doubt as resolved if you will be able to solve it after this.

1 Like


is this correct way?

1 Like

@dhairya16 Ya its totally correct. Nice work!!

1 Like

@dhairya16 Mark this doubt as resolved.

1 Like