The code is showing run-error in one of the test cases. Link:https://ide.codingblocks.com/s/116416
Subset sum problem using DP
Check the modified code:
Note that all positions in the 0th column must be true because 0th column denotes target sum as 0 which can be attained using an empty subset.So dp[i][0]=true where i is from 0 to n.
Also the 0th row denotes 0 element considered…so all dp[0][i]=false where i is from 1 to target sum.
After that start filling the dp table as you have done.
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.