We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
stringfairRations(vector<int>B){intcost=0;intoddIndex=-1;for(size_ti=0;i<B.size();i++){if(B[i]%2==0){continue;}// Everything from here is ODD...if(oddIndex==-1){oddIndex=i;continue;}// Odd Index is never -1 after this...cost=cost+i-oddIndex;oddIndex=-1;}if(oddIndex!=-1){return"NO";}returnto_string(cost*2);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Fair Rations
You are viewing a single comment's thread. Return to all comments →
Rate my unique solution!!!