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:
current run sum 0
best sum 0