TypeScript Max Double Slice Sum
function maxDoubleSliceSum(a: number[]): number {
  const size = a.length;
  if (size < 3) {
    return 0;
  }

  const p1: number[] = new Array(size).fill(0);
  const p2: number[] = new Array(size).fill(0);
  p1[1] = 0;
  p2[size - 2] = 0;

  for (let i = 2; i < size - 1; i++) {
    p1[i] = Math.max(0, p1[i - 1] + a[i - 1]);
    p2[size - i - 1] = Math.max(0, p2[size - i] + a[size - i]);
  }

  let sum = p1[1] + p2[1];
  for (let i = 1; i < size - 1; i++) {
    sum = Math.max(sum, p1[i] + p2[i]);
  }

  return sum;
}

This keeps the best sum ending on the left and starting on the right, then combines them around each middle position.