I am getting 80/100

#include <bits/stdc++.h>
using namespace std;

bool subArrayExists(int arr[], int n)
{
unordered_set sumSet;

// Traverse through array and store prefix sums 
int sum = 0; 
for (int i = 0 ; i < n ; i++) 
{ 
	sum += arr[i]; 

	// If prefix sum is 0 or it is already present 
	if (sum == 0 || sumSet.find(sum) != sumSet.end()) 
		return true; 

	sumSet.insert(sum); 
} 
return false; 

}

// Driver code
int main()
{

int t;
cin>> t;
while(t--)
{
	int n;
	cin>> n;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>> arr[i];
	}
        if (subArrayExists(arr, n)) 
	cout << "Yes"<<endl; 
else
	cout << "No"<<endl; 
}
return 0; 

}

hello @sunneykumar309
the logic that u applied is for subarray only.
in question they are asking u to tell whether there exisit any subset or not with 0 sum.
note subset and subarray are different things.

#include <bits/stdc++.h>
using namespace std;
// Returns true if there is a subset
// of set[] with sum equal to given sum
bool isSubsetSum(int set[], int n, int sum)
{
// Base Cases
if (sum == 0)
return true;
if (n == 0)
return false;

// If last element is greater than sum,
// then ignore it
if (set[n - 1] > sum)
	return isSubsetSum(set, n - 1, sum);

/* else, check if sum can be obtained by any 

of the following:
(a) including the last element
(b) excluding the last element */
return isSubsetSum(set, n - 1, sum)
|| isSubsetSum(set, n - 1, sum - set[n - 1]);
}

// Driver code
int main()
{
int t;
cin>> t;
while(t–)
{
int n;
cin>> n;
int set[n];
for(int i=0;i<n;i++)
{
cin>> set[i];
}
int sum = 0;
if (isSubsetSum(set, n, sum) == true)
printf(“Yes”);
else
printf(“No”);

}
return 0 ;

}

still i am getting error
and after watching hint section i am get confused
because she is saying when the (1,2,3) then answer is 2.
How is it possible?

@sunneykumar309
ur approach will also consider empty subset as well .
and becuase empty subset will have 0 sum , ur code will always print yes .
but in question they are asking for non empty subset.
to resolve this issue.
maintain count of 0 sum SUBSET.
if count > 1 then print yes (1 is for empty set)
otherwise print nO

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.