You are viewing a single comment's thread. Return to all comments →
Without set clean code
long maximumSum(vector<long> &a, long m) { long maxSum = 0, currSum = 0; vector<long> currSumVec; for (int i = 0; i < a.size(); i++) { currSum = (currSum + a[i]) % m; maxSum = max(maxSum, currSum); auto it = upper_bound(currSumVec.begin(), currSumVec.end(), currSum); if (it != currSumVec.end()) { long maxi = (currSum - *it + m) % m; maxSum = max(maxSum, maxi); } currSumVec.insert(it, currSum); } return maxSum; }
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 →
Without set clean code