My issue
can anyone help me where am i wrong.
My code
#include <iostream>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
int n,p=1;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
p=a[i]*p;
}
if(p<0) cout<<1<<endl;
else cout<<0<<endl;
}
return 0;
}
Problem Link: NONNEGPROD Problem - CodeChef
@shubham_731
just a little logical mistake
I have corrected it in your code
hope u will get it.
#include <iostream>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
int n,p=1;
cin>>n;
int a[n];
int cnt=0,cnt1=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]<0)
cnt++;
else if(a[i]==0)
cnt1++;
}
if(cnt1==0&&cnt%2) cout<<1<<endl;
else cout<<0<<endl;
}
return 0;
}
can u(anyone) explain me what is wrong in my code. Since my code is satisfying every test cases.
can u(anyone) explain me what is wrong in my code. Since my code is satisfying every test cases.
@shubham_731
The thing is when u are performing the actual multiplication it overflows the integer range and thus giving u wrong answer .
So This is the problem U have to solve without performing the actual multiplication.
Yeah. Multiplication of array elements may leads to overflow which will affect your final multiplication result.