Subarray jumlah maksimum
public static int SumArray()
{
var arr = new int[]{ -2, -4, -5, -6, -7, -89, -56 };
var sum = 0;
var max = arr[0];
foreach (var item in arr)
{
sum += item;
// sum = Math.Max(sum,0); resting here will not give expected output
max = Math.Max(sum,max);
sum = Math.Max(sum,0);
}
return max;
}
PrashantUnity