C# Tape Equilibrium
static long TapeEquilibrium(int[] a)
{
long firstPart = 0;
long secondPart = a.Sum(x => (long)x);
long min = long.MaxValue;
for (int i = 0; i < a.Length - 1; i++)
{
firstPart += i;
secondPart -= i;
var difference = Math.Abs(firstPart - secondPart);
min = difference < min ? difference : min;
}
return min;
}
This keeps left and right running sums and updates the smallest difference at each split point.