int maxso=INT_MIN,maxend=0;
for(int i:A)
{
maxend+=i;
if(maxend>maxso)
maxso=maxend;
if(maxend<0)
maxend=0;
}
return maxso;
Max Sum Contiguous Subarray c++ best solution
9b5ac7c0a
#4
@joshisweta2000_f8cdf thx for pointing out Kadane’s algorithm. Above solution looks like iterative approach of Kadane’s. here is a really good explanation of Kadane’s algorithm https://medium.com/@rsinghal757/kadanes-algorithm-dynamic-programming-how-and-why-does-it-work-3fd8849ed73d