Not getting correct output

#include
using namespace std;
void array(int* a,int n,int i,int* output,int j,int key){

//base case
if(i>=n){
int sum=0;
for(int k=0;k<j;k++){
sum=sum+output[k];
}
if(sum==key){
cout<<“yes”;
cout<<endl;
}else {
cout<<“No”<<endl;
}

return;
}

//recursive case
//exclude
array(a,n,i+1,output,j,key);
//include
output[j]=a[i];
array(a,n,i+1,output,j+1,key);

}
int main() {
int n;
cin>>n;
int a[100];
for(int i=0;i<n;i++){
cin>>a[i];
}
int output[100];
int key=0;
array(a,n,0,output,0,key);
}

hi @uvanshika dear u need to print No in case of empty subset
eg
ans for
1
4
1 1 1 1
will be no as there is no subset with element sum equal to 0 ( without empty subset )

please refer this and do a dry run on paper youll understand better :slight_smile:

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.

1 Like

Could you please check this , no test case is getting passed