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.
I came up with a different approach in O(n) only no need to check for sum.
here return 1 means NO.
// Complete the fairRations function below.intfairRations(vector<int>a){intn=a.size(),r=0;for(inti=0;i<n-1;i++){if(a[i]%2!=0){a[i+1]++;r+=2;}}if(a[n-1]%2==0)returnr;else{return1;}}
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 →
I came up with a different approach in O(n) only no need to check for sum. here return 1 means NO.