getting run error in one test case
ide: https://ide.codingblocks.com/s/253801
Subset sum to target
Check line 17 dp[i][j] = dp[i-1][j] || dp[i-1][j-a[i-1]];
if j-a[i-1] is less than 0, then due to this statement, your code will give a run error. Cross check it and try to correct.
Your code is giving runtime error because you have tried to create an array of large size during runtime. See maximum value of n is 10^5 and k is 5000. In your code you have tried to create dp[n+1][k+1], for maximum value of n and k it become dp[100001][5001] which can’t be possible. We don’t have that much memory allocated for such question.
Refer this https://www.geeksforgeeks.org/subset-sum-problem-osum-space/