Kadane's Algorithm
intermediateFinds the maximum sum contiguous subarray in O(n) by deciding at each step whether to extend or restart.
Current Sum0
Max Sum0
Original Array
-2
[0]1
[1]-3
[2]4
[3]-1
[4]2
[5]1
[6]-5
[7]4
[8]Extend window or start fresh?
Extend:0+-2=0
Restart:-2alone
Current element (examine)
Running window members
New maximum found
1 / 27