Codility Max Slice Sum

Posted on December 10, 2013

Last updated on December 10, 2013

This is Kadane’s Algorithm. The 100/100 Codility code:

public int solution(int[] A) {
    int maxEndingHere = A[0];
    int maxSoFar = A[0];
    for(int i = 1; i < A.length; i++){
        maxEndingHere = Math.max(A[i], maxEndingHere + A[i]);
        maxSoFar = Math.max(maxSoFar, maxEndingHere);
    }
    return maxSoFar;
}
Max Slice Sum
Markdown SHA1: a904b5754cfbbf4f4c91276b549328bb21582254