You are viewing a single comment's thread. Return to all comments →
Thanks , i tried to implement your idea .
public static String fairRations(List<Integer> B) { Integer pub[]= new Integer [B.size()]; pub=B.toArray(pub); int count_odd=0,count=0,l=-1,r=-1; for(int i=0;i<pub.length;i++) { if(pub[i]%2!=0) count_odd++;; } if(count_odd%2!=0) return "NO"; else { for(int i=0;i<pub.length;i++) { if(pub[i]%2!=0) { if(l==-1 ) { l=i; } else if(l!=-1 && r==-1) { r=i; } if(l!=-1 && r!=-1) { count+=(r-l); l=-1; r=-1; } } } } count*=2;
return 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 →
Thanks , i tried to implement your idea .
return count+"";