Skip to content

Instantly share code, notes, and snippets.

@kshcherban
Created October 26, 2022 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kshcherban/760c8f018899eef746fc0861fa329be6 to your computer and use it in GitHub Desktop.
Save kshcherban/760c8f018899eef746fc0861fa329be6 to your computer and use it in GitHub Desktop.
def consequitive_max_sum(int_list):
# last_seq = []
max_sum = sum(int_list)
for index, val in enumerate(int_list):
new_sum = sum(int_list[index:])
if new_sum > max_sum:
max_sum = new_sum
# for index, val in enumerate(int_list):
# last_sum = sum(last_seq)
# last_seq.append(val)
# new_sum = sum(last_seq)
# if new_sum > last_sum and new_sum > max_sum:
# max_sum = new_sum
# last_seq = [val]
# last_seq = []
# for val in reversed(int_list):
# last_sum = sum(last_seq)
# last_seq.append(val)
# new_sum = sum(last_seq)
# if new_sum > last_sum and new_sum > max_sum:
# max_sum = new_sum
# last_seq = [val]
return [max_sum]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment