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.
int key=0;
for(int i = 0;i < B.size()-1;i++){ // because lin last element we have to do other operation
if(i == B.size()-1){ //this is for last element only
if(B[i] % 2!=0){
B[i]++;
B[i-1]++;
}
}
if( B[i] % 2 !=0){
B[i]++;
B[i+1]++;
key+=2;
}
}
bool flag = 1;
for(int i = 0;i < B.size() ; i++){
if(B[i] % 2!=0){
flag=0;
break;
}
}
if( flag ==0){
return "NO";
}
else{
return to_string(key);
}
}
Cookie support is required to access HackerRank
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 →
very simple and uderstable solution with cpp
string fairRations(vector B) {
}