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.
- Prepare
- Algorithms
- Search
- Maximum Subarray Sum
- Discussions
Maximum Subarray Sum
Maximum Subarray Sum
Sort by
recency
|
341 Discussions
|
Please Login in order to post a comment
No need to use tree or sorted set. Just store all the prefix sums and sort. This idea comes from a different problem of minimising loss on house purchasing.
pure java... package geeksforgeeks; import java.util.*;
public class Maxnumber {
}
pure java... package geeksforgeeks; import java.util.*;
public class Maxnumber {
}
This is my idea
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; }