You are viewing a single comment's thread. Return to all comments →
In this problem the thing is if sum of all number is even ,then array can be even. if sum of all number is odd , then the answer is NO.
My java solution is here;
public class Solution {
public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); int B[] = new int[N]; int sum = 0; for(int B_i=0; B_i < N; B_i++){ B[B_i] = in.nextInt(); sum+=B[B_i]; } int count = 0; if(sum % 2 == 1){ System.out.println("NO"); } else{ for(int i = 0; i<N; i++){ if(B[i] % 2 != 0){ B[i] = B[i] + 1; B[i+1] = B[i+1] + 1; count+=2; } } System.out.println(count); } }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Fair Rations
You are viewing a single comment's thread. Return to all comments →
In this problem the thing is if sum of all number is even ,then array can be even. if sum of all number is odd , then the answer is NO.
My java solution is here;
public class Solution {
}