My issue
I count the number of even and the number of odd numbers. if the number of odd numbers are even that is all the odd numbers can be paired then the result should be 1. But if the number of odd numbers is odd, this means that one odd number will be remaining at the end of the pairing. So, the answer should be 2. As we know sum of n even numbers are always even but some of n odd numbers can even if the n is even and will be odd if the n is odd. I applied the same logic to code, but, for some unknown reason a hidden case keeps on failing.
My code
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
vector<int> a(n);
int count_even = 0, count_odd = 0;
for (int i = 0; i < n; i++)
{
cin >> a[i];
if (a[i] % 2 == 0)
{
count_even++;
}
else
{
count_odd++;
}
}
int result = (count_odd % 2 == 0) ? 1 : 2;
cout << result << endl;
}
return 0;
}
Problem Link: Chef and Game with Sequence Practice Coding Problem