Skip to content

Instantly share code, notes, and snippets.

@hiddenist
Last active December 25, 2015 05:39
Show Gist options
  • Save hiddenist/6926596 to your computer and use it in GitHub Desktop.
Save hiddenist/6926596 to your computer and use it in GitHub Desktop.
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