not sure that all these propositions are working in real cases : let's consider this array :
t = [ -1,-2,10,11,-2,-1 ]
none of your solutions seem to consider a sub sum that can be bounded inside the array.
I feel like a solution with two iterators should fit.
a function sum(int beg, int end, int* array) returning the sum between the indexes.
and something like :
int highestConsecutive(int* array){
int beg=0, end=len(array);
int biggest_sum=-MAXINT;
for(end=len(array);end>0;--end){
for(beg=0; beg < end; ++beg){
int s_btw=sum(beg,end);
biggest_sum=s_btw;
}
}
return biggest_sum;
}
should return the highest consecutive sum....
I've not tested it since I've juste been writing it here, but I think that it's on the way to a correct solution, and it seems to have something like an n*log(n) complexity.
such a solution even allows you to return the indexes of the sum found...
this have to be checked and optimized but still...