Why I am getting run-time error ?
0-N Knapsack Problem
@vaishnavtannu two mistakes corrected and commented
dont forget to hit like and mark resolved if cleared
But why 2D dp is needed, as N will not change in case of 0-N Knapsack ?
Okay, Got it. But as explained in solution video that we can do it using 1D DP by considering the weights only how can we do that in top down manner ?
@vaishnavtannu it can be done with 1d dp too like you have done but i think it will be not optimal.
just in your code do n-1 in exclude then it will give correct for small cases
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.