Answers for "kadane algorithm actual"

0

kadane algorithm actual

//Kadene's algorithm where empty array is allowed.

int ms,cs;
	    ms=cs=0;
	    for(int i=0;i<n;i++)
	    {
	        cs=cs+a[i];
	        if(cs<0)
	        {
	            cs=0;
	        }
	        ms=max(ms,cs);
	}
	cout<<ms<<endl;
	}
Posted by: Guest on October-23-2020

Browse Popular Code Answers by Language