showing run time error.Pl tell th mistake
Subset sum easy question
@ayush15goel hey ayush your recursive code is not right it should be like
bool isSubsetSum(long long * arr, long long sum, long long n)
{
if( n == 0 ) return false;
int ans = 0;
ans=sum+arr[n-1];
if(ans==0) return true;
// including the last element
// and not including the last element
return isSubsetSum(arr,ans,n-1) || isSubsetSum(arr,sum,n-1);
}
sir cant understand the error.
@ayush15goel hey ayush your function is not right your code is going in infinite computational you can check this on onlinegdb.com this compiler will give you a visualization after some function call you code is breaking and if you dry run on your logic you will find your mistake also base case is also wrong . use the suggested one.
Sir , could not write the correct code.Can you pl make corrections in the code I shared
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.