Why it is showing failed testcases..i have implemented using dp only

hello @garganshul151

it is taking too much space (as per constaint)
ur solution space complexity should be O(n).

refr this for O(n)->https://www.geeksforgeeks.org/subset-sum-problem-osum-space/

i got it but donot get the role of (i%2)in optimizing the space…plz tell me that

to convert index i to either 0 or 1 we r taking mod with 2

that i underatood but how will it help?how can i overwrite the things…also how can i store 0 value in 1

in this problem dp[i][j] depends only on previous row i.e i-1.
so what we r doing is we are only using two rows.
one row to storre previous (i-1) and other row for i.

so here 0 and 1 is acting as current and previous row .
if i%2 is current row then !(i%2) will act as previous row

there are many problems in which current depends on previous only like knapsack or lcs…can i implement it to that too?

yeah…

thank yoy…plz relly to my 1 count problem too

thank yoy…plz reply to my 1 count problem too

i am not taking that doubt , someone else is taking

mohit pandey has replied that he couldnot find any error…can u plz see to it?