I need a running python script that can handle this problem, im so confused and
ID: 671179 • Letter: I
Question
I need a running python script that can handle this problem, im so confused and sont know where to start. Thanks for any time taken to help!
write function mssl() (minimum sum sublist) that takes as input a list of integers. It then computes and returns the sum of the maximum sum of the maximum sum sublist of the input list. The maximum sum sublist is defined to have sum 0. For example, the maximum sum sublist of the list,
[4,-2,-8,5,-2,7,7,2,-6,5] is [5,-2,7,7,2] and the sum of its entries is 19.
>>>1=[4,-2,-8,5,-2,7,7,2,-6,5]
>>>mssl(1)
19
>>>mssl([3,4,5])
12
>>>mssl([-2,-3,-5])0
Explanation / Answer
working python code compiled on ideone
def mssl(list):
best = current = 0
for i in list:
current = max(current + i, 0)
best = max(best, current)
return best
print mssl([4,-2,-8,5,-2,7,7,2,-6,5])
http://ideone.com/bJtoXN
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.