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.
bool myCompare(pair a,pair b){
bool res;
if (a.first==b.first) {res=(a.second
long maximumSum(vector a, long m) {
long res=m,sumA=0;
vector > vp;
vp.push_back(make_pair(sumA,0));
for (uint i=0; i>::iterator itB,itE;
long dFirst;
int dSecond;
for (itB=vp.begin(); itB!=vp.end(); itB++){
itE=itB+1;
if (itE==vp.end()) {itE=vp.begin();}
dFirst=(m+(*itE).first-(*itB).first)%m;
dSecond=(*itE).second-(*itB).second;
if (dFirst>0&&dSecond<0) {res=min(res,dFirst);}
}
return m-res;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Subarray Sum
You are viewing a single comment's thread. Return to all comments →
bool myCompare(pair a,pair b){ bool res; if (a.first==b.first) {res=(a.second
long maximumSum(vector a, long m) { long res=m,sumA=0; vector > vp; vp.push_back(make_pair(sumA,0)); for (uint i=0; i>::iterator itB,itE; long dFirst; int dSecond; for (itB=vp.begin(); itB!=vp.end(); itB++){ itE=itB+1; if (itE==vp.end()) {itE=vp.begin();} dFirst=(m+(*itE).first-(*itB).first)%m; dSecond=(*itE).second-(*itB).second; if (dFirst>0&&dSecond<0) {res=min(res,dFirst);} } return m-res; }