You are viewing a single comment's thread. Return to all comments →
JAVA
public static String fairRations(List B) { // Write your code here
int count = 0; for(int i=0;i<B.size();i++){ int num = B.get(i); if(B.get(i)%2!=0){ B.set(i,num+1); count++; if(i==B.size()-1){ B.set(i-1,B.get(i-1)+1); count++; }else{ B.set(i+1,B.get(i+1)+1); count++; } } } boolean flag = true; for(int i=0;i<B.size();i++){ if(B.get(i)%2!=0){ flag = false; break; } } String result = ""+count; if(flag==true){ return result; }else{ return "NO"; } }
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 →
JAVA
public static String fairRations(List B) { // Write your code here