My issue
What’s the need to introduce “count_zero” variable, as given in the solution.
Even if there is a single 0 in the array, the product is non-negative.
My code
// Solution as follows
#include <bits/stdc++.h>
using namespace std;
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];
}
int count_neg = 0;
for(int i = 0; i < N; i++)
{
if(A[i] == 0)
{
cout<<0<<endl;
}
if(A[i] < 0)
{
count_neg++;
}
}
if( (count_neg%2 == 0))
{
cout << 0 << endl;
}
else
{
cout << 1 << endl;
}
}
}
Learning course: C++ for problem solving - 2
Problem Link: CodeChef: Practical coding for everyone