Why testcase3 is failing in this code

#include
#include
using namespace std;
void zerosum(int *a, int n, int sum ,int i ){
if( i== n){
cout << “No”<< endl;
return;
}
sum += a[i];
if( sum == 0){
cout << “Yes” << endl;
return;
}
zerosum( a, n,sum, i+1);
}
int main() {
int t;
cin >> t;
while( t–){
int n;
cin >> n;
int a[n];
for( int i = 0; i < n; i++){
cin >> a[i];
}
sort(a, a+n);
zerosum(a,n,0,0);

}
return 0;

}

your approach is wrong
you are taking simple sum of array
but in question you have to find whether if the sum of any of the non-empty subsets of the array is zero or not.

for this input
5 4 6 -3 -2
Your code output is NO
but there exists a subset {5,-3,-2} whose sum is zero

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.