The dp approach is not working in my code

Hello @varun.saxena,

The memorization should be based on two parameters i.e. n and size.
IT is a question of 2D DP.

Even if you wanna solve it with 1D DP, you have to consider both n and size in account while memorization.

See the following article:
https://www.techiedelight.com/0-1-knapsack-problem/

Hope, this would help.