Why is this code giving TLE for Knapsack 1
Why is this code giving TLE for Knapsack 1
hello @cbcao263
ur code is correct, but because solution is pure recursive without memoisation/ dp it is giving tle.
apply memoisation to pass all test cases
Even Now it is not workking
u should use 2d array for memoisation
dp[n][w] .this should be ur dp state
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.