Difficulty:
easy
Hint:
The array must contain an even number of odd and even integers.
Explanation:
Since (even + even) and (odd + odd) give an even integer, the number of even and odd integers must be divisible by 2.
Basically, for every odd integer, there must be another odd integer to make a pair with an even sum, symmetrically for every even integer there must be another even integer to make a pair with an even sum.
Setter’s Solution:
#include <bits/stdc++.h>
using namespace std;
int main(){
int T;
cin>>T;
while(T--){
int N;
cin>>N;
int eve = 0, odd = 0;
for(int i = 0; i< 2*N ; i++){ int k;
cin>>k;
if(k%2==0)
eve++;
else
odd++;
}
if(eve%2==0 && odd%2==0)
cout<<"TRUE"<<"\n";
else
cout<<"FALSE"<<"\n";
}
return 0;
}
Time Complexity:
O(2N)
Space Complexity:
O(2N) for storing the given array.
Python Implementation:
for t in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
odd = 0
even = 0
for a in arr:
if a%2==0:
even+=1
else:
odd+=1
if odd%2 == 0 and even%2 == 0:
print("TRUE")
else:
print("FALSE")
Author: Siddharth Bharmoria - papa_pengu1n
Tester: Ramandeep - ramandeep8421
Editorialist: Siddharth Bharmoria - papa_pengu1n