cumsum[i-1] will get a negative value cumsum [-1] at i=0 and will show error. how to solve it?
Maximum subarray sum
It can be solved by writing cum[-1]=0;
@sharmaharsh9944
That would be wrong as we are accessing invalid memory location. We solve this problem by assigning value of a[0] to cumSum[0] before the loop and start the loop from i = 1
cumSum[0] = a[0];
for ( int i = 1; i <n ;i++)
{
cumSum[i] = cumSum[i-1] + a[i] ;
}