The basic idea is to scan the entire array and at each position find the maximum sum of the sub-array ending there. This is achieved by keeping a currentMax for the current array index and a globalMax.
Let’s see how we might implement this functionality:
Initialize a currentMax and a globalMax and assign them the first value of the array.
Traverse the array starting with the second element.
For each element, check whether currentMax is less than zero:
If it is less than zero, assign it the current element as its value
Otherwise, add the current element in the currentMax
Similarly, for each element check if globalMax is less than currentMax then assign globalMax equal to the value of currentMax
The following illustration might clarify this process.