Why everyone is trying to take an array and then evaluate the sum. There’s no need of it at all.
We just need to look for number of odd elements in the array. if number of odd elements is even then sum is always even.if number of odd elements is odd them sum is always odd.
enter code here
import java.util.*;
import java.math.*;
import java.util.regex.Pattern;
public class check {
// Driver code
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t>0){
int n=sc.nextInt();
int k=sc.nextInt();
int count=0;
for(int i=0;i<n;i++){
if(sc.nextInt()%2!=0){
count++;
}
}
if(count%2==0){
if(k==1)
System.out.println(“odd”);
else
System.out.println(“even”);
}else{
Plz can someone point out mistake in my code plz.Here is my code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
long long int n,k,i,s=0;
cin>>n>>k;
long long int a[n];
for(i=0;i<n;i++){