I'm not sure what's wrong. I assume I have surpassed an array limit perhaps.
def lcs(arr):
if len(arr) == 0: # arr of length 0
return
sumarr = []
counter = 0
sum = 0
for i in arr:
if arr[i] > 0:
sum = sum + arr[i]
if arr[i] < 0:
sumarr[counter] = sum
counter += 1
print max(sumarr)
The error I get is:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 8, in lcs
IndexError: list index out of range
#
I've modded the code a bit
def lcs(arr):
if len(arr) == 0: # arr of length 0
return
sumarr = []
counter = 0
sum = 0
for i in arr:
if i > 0:
sum = sum + i
if i < 0:
sumarr[counter] = sum
counter += 1
print max(sumarr)
However I'm getting this error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 13, in lcs
ValueError: max() arg is an empty sequence
I thought I was constantly updating my sumarr[]. How come the error is telling me that I am passing an empty list into max()?