Subset sum problem

sir, how can we approach when target sum is zero

there would be two cases

  1. if A[i] > 0 then ans would always be zero
  2. if A[i] >=0 then answer would be 2^n’-1 where n’ would be number of elements in the array with value 0
  3. A[i] is integer , then we have to apply the same algo but have to use hash map for storing repetetive values

In case of any doubt feel free to ask :slight_smile:
mark your doubt as resolved if you got the answer

sir ,i don’t got it please explore again

case 1;
assume u have a array with only positive values then there is no way we can have a subset with sum 0 thus answer will always be FALSE
case 2:
lets assume we have array with values >= 0 , then if there is any element in the array with value 0 only then the answer will be YES
case 3:
we can have positive as well as negetive number , then you have to apply same recurence relation and use dp to optimize it . but we have to use map for that as sum can be negetive and in array we cannot have negetive indexing

thank you,sir got it

In case of any further doubt feel free to ask :slight_smile:
If u got the answer then mark your doubt as resolved

ok sir why comment length is >=20

can you explain what do u mean ?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.