In the Bottom Up Dp and Top Down Dp Approach two test cases are showing TLE.
TLE In Two Test Cases
i guess thats because of the way u are declaring the 2d dp array
i dont know why this is happening
ur code is correct changing the definition leads to correct asnwer
bool **dp = new bool*[n+1];
for(int i=0;i<=n;i++) {
dp[i] = new bool[target+1];
}
dp[0][0] = true; // If sum is zero and no element is taken ans is true
for(int i=1;i<=n;i++) { // If sum is zero ans is always true
dp[i][0] = true;
}
for(int i=1;i<=target;i++) { // If no element is chosen and sum is not zero ans is false
dp[0][i] = false;
}
