(Hacker Rank) Even Training - Solution

Link to the problem: https://www.hackerrank.com/contests/womens-codesprint/challenges/even-training

This is a problem where all you need to do is to check if the amount of '1's is even or odd.


import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int sum = 0;
        for(int a_i=0; a_i < n; a_i++){
            if (in.nextInt() == 1) {
                sum++;
            }
        }
       
        if (sum%2 == 0) {
            System.out.println("Yes " + sum);
        }
        else {
            System.out.println("No " + sum);
        }
       
       
    }
}

Comments

Popular posts from this blog

(Coderbyte) Powers of Two - Solução

(Coderbyte) Dash Insert II - Solução

(CoderByte) Number Search - Solução