Codility 'MaxSliceSum' Solution | MartinKysel.com
Find a maximum sum of a compact subsequence of array elements.
http://rafal.io/posts/codility-max-slice-sum.html
Find a maximum sum of a compact subsequence of array elements.
http://rafal.io/posts/codility-max-slice-sum.html
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;
}
Read full article from Codility 'MaxSliceSum' Solution | MartinKysel.com