Subset sum easy problem

#include <bits/stdc++.h>
using namespace std;
int cnt=0;
void sum(vector arr,int index,vector sub){

if(index==arr.size()){
    int l = sub.size();
    if(l!=0){
            int sum=0;
        for(int i=0;i<l;i++){
            sum=sum+sub[i];
        }
    if(sum==0){
        cnt++;
    }
    }
    return;

}

sum(arr,index+1,sub);
sub.push_back(arr[index]);
sum(arr,index+1,sub);

}

int main(){
int t;
cin>>t;
while(t–){
int n;
cin>>n;
vector arr;
vector sub;
for(int i=0;i<n;i++){
int a;
cin>>a;
arr.push_back(a);
}
sum(arr,0,sub);
if(cnt>=1){
cout<<“Yes”<<endl;
}
else
cout<<“No”<<endl;

}
return 0;

}

what is the problem with my program I can’t figure out it is working for sample cases

can you share the problem statement and constraints

https://hack.codingblocks.com/app/practice/1/1083/problem

In your code cnt variable is global, and once it is positive it will remain positive and output “YES” is every test case thereafter,
So, inside while loop do the following and try again:

while(t–){
cnt=0;

rest of the code

}

1 Like

thank you i don’t know how i missed it

If you have no doubt then mark it as resolved and rate us!
Regards