kadane algo

PHOTO EMBED

Sun Jul 12 2020 21:32:42 GMT+0000 (UTC)

Saved by @gagandeepgarg6 #java

public static int kadanesAlgorithm(int[] array) {
   
int maxEndingHere = array[0];
int maxSoFar = array[0];
		
for(int i=1; i<array.length; i++){
			
maxEndingHere = Math.max(maxEndingHere+ array[i], array[i]);
maxSoFar = Math.max(maxSoFar, maxEndingHere);
			
}
return maxSoFar;
}
content_copyCOPY