Kadane's Algorithm

Array Presets

Algorithm Loop

1. Add to Current Sum Pending
2. Update Max Sum Pending
3. Reset if Negative Pending

The Power of O(N)

We maintain a running Current Sum. If it ever drops below 0, the contiguous subarray is "dragging us down", so we reset it back to 0 and start fresh from the next element.

Meanwhile, Max Sum blindly tracks the highest peak we ever reach!

Live Console Log

Waiting for actions...

Current Sum

0

Max Sum

-∞