Maximum Subarray — Kadane's algorithm
Carry a running sum across the array. Whenever that sum turns negative it can only drag the next number down, so drop it and start fresh. Track the best sum seen.
Try:
← Prev
Next →
▶ Play
Reset
current run sum
0
best sum
0