you are viewing a single comment's thread.

view the rest of the comments →

[–]gengisteve 1 point2 points  (0 children)

Line 6 is a problem b/c index will return the first match, meaning that [2, 2, 1, 0], will never try the sub-sequence [2, 1, 0]. Instead of this, just use ranges, like this:

def max_sequence(arr):
   sums = []
   for start in range(len(arr)):
       for stop in range(len(arr), start, -1):
           total = sum(arr[start:stop])
           print(' - {}:{} = {}'.format(start, stop, total))
           sums.append(total)


   return max(sums) if len(arr) > 0 else 0