Balanced Array | Interview Question
static int solve(int[] a){
if(a.Length % 2 == 0)
{
int firsthalf = a.Take(a.Length / 2).ToArray().Sum();
int secondhalf= a.Skip(a.Length / 2).ToArray().Sum();
if(firsthalf == secondhalf)
{
return 0;
}
else if (firsthalf > secondhalf)
{
return firsthalf - secondhalf;
}
else if (secondhalf > firsthalf)
{
return secondhalf - firsthalf;
}
return 0;
}
return 0;
}