Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Calculate the maximum consecutive sum in a sequence of numbers
# Return the maximum consecutive sum in a list of numbers
def max_consecutive_sum(values):
m = None
prev = None
for value in values:
cur = value + max(prev, 0)
m = max(cur, m)
prev = cur
return m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.