Subset sum easy(hacker blocks)

i am not able to get the correct output and i ve checked the code many times couldn’t find any logical or syntax error.
please help,

code is below-

#include
using namespace std;
bool sum(int *arr,int n){
int s=0;
for(int i=0;i<n;i++){
s+=arr[i];
}
if(s==0){
return true;

}else{
    return false;
}

}
bool sub(int *arr,int i,int *input){
int j=0;
int p=0;
while(i>0){
if(i&1){
input[p++]=arr[j];
}

j++;
i>>1;

}
if(p>0)
return sum(input,p);
else
return false;

}
bool check(int *arr,int n){
int input[n];
bool x=false;
for(int i=0;i<(1<<n);i++){
x=x or sub(arr,i,input);
}
return x;
}
int main() {
int t;
int n;
int arr[n];
cin>>t;
while(t–){
cin>>n;
for(int i=0;i<n;i++){
cin>>arr[i];
}
bool p=check(arr,n);
if(p==true){
cout<<“Yes”;
}
else
{
cout<<“No”;
}

}
return 0;

}

There are many mistakes here rishabh
One is You have declared arr[n] before taking n as input. Its better to pass code by pasting it in ide.
Remove compilation errors, so that we can focus on correcting your logic

1 Like

Here’s a much simpler solution
#include<bits/stdc++.h>
#define ll long long
using namespace std;
main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t,n,i;
cin>>t;
while(t–)
{
cin>>n;
int a[n];
ll prefix_sum[n];
for(i=0;i<n;i++)
{
cin>>a[i];
if(i!=0)
prefix_sum[i]=prefix_sum[i-1]+a[i];
else
prefix_sum[i]=a[i];
}
unordered_set s;
bool flag=false;
for(i=0;i<n;i++)
{
if(prefix_sum[i]==0)
{
flag=true;
break;
}
if(s.find(prefix_sum[i])!=s.end())
{
flag=true;
break;
}
else
s.insert(prefix_sum[i]);
}
flag?cout<<“Yes\n”:cout<<“No\n”;
}
}