Non-Negative Product doubt

#include // iostream included - here it is not displaying
using namespace std;

int main() {
long long int t,n,i,p=1;
cin>>t;
while(t–)
{
cin>>n;
long long int a[n];
p=1;
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
p=p*a[i];
}
if(p>=0)
cout<<“0”<<endl;
else
cout<<“1”<<endl;
}
return 0;
}

// why this solution is not acceptable?

long long int Overflow!
And you may count the number of negative numbers in the sequence.
If it’s odd,the answer is 1,otherwise the answer is 0.

1 Like

Oh,and don’t forget to check whether there is 0 in the sequence.

1 Like

Thanks @yyandy

Great explaination!!

1 Like