plz correct the code it is not passing all test cases…expalain as well.
Subset sum problem
this is the correct code for it
but on 2nd TC it will give run 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. Try recursion to solve this question.
Or
If you want to stick to this approach
allocate the memory dynamically like this solution, with same logic