Skip to content

Instantly share code, notes, and snippets.

@amitm
Created October 11, 2013 14:13
Show Gist options
  • Save amitm/6935319 to your computer and use it in GitHub Desktop.
Save amitm/6935319 to your computer and use it in GitHub Desktop.
def max_consecutive_sum(nums):
max_sum = nums[0]
current_sum = 0
for i in nums:
current_sum += i
if current_sum > max_sum:
max_sum = current_sum
if current_sum <= 0:
current_sum = 0
return max_sum
if __name__ == '__main__':
print max_consecutive_sum([-1, 5, -1, -2, 20, -50, 4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment