• + 0 comments

    Java Solution:

    public static String fairRations(List<Integer> B) {
            int[] arr = B.stream().mapToInt(Integer::intValue).toArray();
            int count = 0;
            for(int i = 0; arr.length>1 && i< arr.length; i++){
                if(arr[i]%2 != 0 && i + 1 < arr.length) {
                    arr[i]++;
                    arr[i + 1]++;
                    count += 2;
                }
            }
            return arr[arr.length-1]%2 == 0 ? String.valueOf(count) : "NO";
        }