This is taken from exercise 4.1-5 of the Introduction to Algorithms Book.
Since this question and its answer addresses this. I think this may be helpful.
"Use the following ideas to develop a nonrecursive, linear-time algorithm for the maximum-subarray problem. Start at the left end of the array, and progress toward the right,keeping track of the maximum subarray seen so far. Knowing a maximum subarray of A[1.. j] , extend the answer to find a maximum subarray ending at index j + 1 by using the following observation: a maximum subarray of A[1.. j + 1] is either a maximum subarray of A[1.. j] or a subarray A[i .. j +1] , for some 1 <= i<= j + 1. Determine a maximum subarray of the form A[i... j+1] in constant time based on knowing a maximum subarray ending at index j."
Answer
First we need to figure out the maximum sub array ending at index j + 1 which could be just A[j + 1] or the maximum subarray ending at j plus A[j+1] , therefore we find the max of this two.
Once we have the maximum sub array ending at index j + 1 we find the maximum of A[1..j+1] by again, getting the max between maximum sub array ending at index j + 1 and maximum subarray of A[1..j].
So basically the idea is getting the maximum sub array ending at the current index of each iteration and getting the max between this and the max of the previous iteration.
Also I think this is incorrect
Edit: This will depend on definition, if the array doesn't need to contain at least one positive number. Otherwise yours is OK.
max_ending = max(0, max_ending + number);
it should be :
max_ending = max(number, max_ending + number);
Also max_ending and max_so_far should start at numbers[0] and the loop at index 1, if you follow mi change.
The complexity for this algorithm is O(n)
Additional note:
In your version there is no need to get the max between number and max_ending + number because max_ending >= 0 so number <= number + max_ending