You are viewing a single comment's thread. Return to all comments →
Here is my Python solution!
def maximumSum(a, m): prefixes = [(0, -1)] for i in range(len(a)): prefixes.append(((prefixes[-1][0] + a[i]) % m, i)) prefixes.sort() maximum = prefixes[-1][0] for (a, i1), (b, i2) in zip(prefixes[:-1], prefixes[1:]): if b > a and i1 > i2: maximum = max(maximum, (a - b) % m) return maximum
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 →
Here is my Python solution!