Start with calculating the sum of the B numbers on the left side of the list
Then loop, substracting one from the left and adding on from the right of the list.
At every step, store the sum if it’s the higher than the previously stored sum.
return the maximum sum seen:
def solve(self, A, B): Sum = Max = sum(A[:B]) N = len(A) for b in range(1, B+1): Sum = Sum - A[B - b] + A[N - b] if Sum > Max: Max = Sum return Max