Skip to content

Commit

Permalink
max sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
Hakan authored and Hakan committed Jul 16, 2020
1 parent 8e85174 commit aaaf0d7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions 027_max_sum_sub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4] # should be 6: [4, -1, 2, 1]


# def maxSequence(arr):
# return max([sum(arr[i:j]) for i in range(len(arr)+1) for j in range(len(arr)+1)])
# print(maxSequence(arr))

def maxSequence(arr):
summ=[]
for j in range(len(arr)+1):
for i in range(len(arr)+1):
summ.append(sum(arr[i:j]))
return max(summ)
print(maxSequence(arr))

0 comments on commit aaaf0d7

Please sign in to comment.