I implemented this by reading about Kadane’s algorithm for sum of subsequences
def kadane(arr):
max_current = arr[0]
globalSum = 0
for x in arr[1:]:
max_current = max(x, max_current + x)
globalSum = max(globalSum, max_current)
return globalSum
But for
arr4 = [1, 400, 7, -2, 0, 15]
the subarray should be 1+400+7+0+15, without the -2, giving 423 as answer. Moreover when I run I have 421 as answer because it considers the -2.
Any idea where I got lost?