Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

kadane algorithm with negative numbers included as sum

//Usually Kadene's algorithm is not considered for negative numbers.   
  int ms,cs;
	    ms=cs=a[0]; 
	    for(int i=1;i<n;i++)
	    {
	        cs=max(a[i],cs+a[i]);
	       ms=max(cs,ms);
	}
return ms;
 
PREVIOUS NEXT
Tagged: #kadane #algorithm #negative #numbers #included #sum
ADD COMMENT
Topic
Name
2+4 =