Concept Flow - Kadane's Algorithm Maximum Subarray
Start
Initialize max_so_far = arr[0
For each element x in array
Add x to max_ending_here
If max_ending_here < 0?
Yes→Reset max_ending_here = 0
No
If max_so_far < max_ending_here?
Yes→Update max_so_far = max_ending_here
Repeat for next element
End: max_so_far is max subarray sum
The algorithm scans the array, adding elements to a running sum. If the sum drops below zero, it resets. It keeps track of the highest sum found.
