l = [2,1,5,1,3,2]
subarrays are [2,1,5], [1,5,1], [5,1,3], [1,3,2]
output is [5 ,1 ,3] which is 9
My code is
def maxcosu(arr,k):
maxtotal = 0
for i in range(len(arr)-k):
total = 0
for j in range(i, i+k):
total = total + arr[j]
maxtotal = max(maxtotal, total)
return maxtotal
maxcosu([2,1,5,1,3,2] , 3)
But for [1,1,1,8,8,8] my expected output is 24, but I am getting 17.
I have gone through this link and the answer by zeeshan12396 is wrong for test case