Python Max Double Slice Sum
def max_double_slice_sum(a: list[int]) -> int:
size = len(a)
if size < 3:
return 0
p1 = {1: 0}
p2 = {size - 2: 0}
for i in range(2, size - 1):
p1[i] = max(0, p1[i - 1] + a[i - 1])
p2[size - i - 1] = max(0, p2[size - i] + a[size - i])
total = p1[1] + p2[1]
for i in range(1, size - 1):
total = max(total, p1[i] + p2[i])
return total
This keeps the best sum ending on the left and starting on the right, then combines them around each middle position.