Getting MLE and WA in 1 test case!
Hey you are getting WA because you haven’t used modulo
& you are getting MLE because you have to solve this in O(N) space right now you are using ou O(n*N)space .
Hint to reduce space: you only need 2 dp rows ,prev row and current row .
okay okay , i will try these corrections and i got the hint as well , thnx
getting TLE in 2 test cases !!
Constraints must be tight ,
try declaring vectors locally so that you dont have to use clear and resize (extra computation)
also this can be further reduced to O(N) space soln try that as well.
it is just O(n*2) which is O(n) right ??
still getting TLE
strange but now i am getting tle in 6 test cases , while earlier it was 2 test cases only !!
Yes but it can be reduced to 1*n ,In the meanwhile I will check your code.
Here I reduced it to O(n) space which also helped to remove if else & %2 etc .
So extra computation is removed,constraints must be very tight in this one.
how this 1dp is used here ?? i mean dp[j] + dp[j-s[i] ] , will it still work if s array is not sorted in ascending order .
hey Assume we are using 2 rows
so while filling second row we always add 1st row to 2nd row
and if (j>=s[i]) in that case we also add dp[i][j-s[i]]
So see here 1d array will do the same
In 1d array
We already have old in current row and only need to add dp[j-s[i]] whenever j>=s[i]
okayy okayy got it got it !! thank you so much !!
btw still tle in 1 test case
It worked on my side ,let me check again
Hey ,yes the code I sent is working on my side for all the testcases. Please go through it again.
ohhh yeahhh worked now , strange !! ,thnx btw !!