I have been solving exercise from Introduction to Algorithms - CLRS and came across solving maximum contiguous sub-array in linear time (Q 4.1-5). Please look at my solution below. I have been searching for online judges for this exercise but found none. After solving it when I looked for solutions I found kadane's algorithm which seems different than my implementation also this solution gives the correct output when all numbers are negative.
public static int linearMaxSolve(int[] arr) {
int max = Integer.MIN_VALUE;
int sum = 0;
for (int i : arr) {
sum += i;
if (i > sum) {
sum = i;
}
if (sum > max) {
max = sum;
}
}
return max;
}
Is there a way to check the validity of this algorithm apart from feeding in manual test cases to the program?