Problem statement
You are given an array of whole numbers, which may be negative. Find the run of neighbouring values whose total is as large as possible, and report that total. If the problem version asks, also report where the run starts and ends.
The run must be a single stretch of the array with no gaps, and it must contain at least one value.
Examples
Input[-2, 1, -3, 4, -1, 2, 1, -5, 4]
Output6
The best run is 4, -1, 2, 1 starting at index 3.
Input[-3, -1, -2]
Output-1
All values are negative, so the best run is the single largest value.
The walkthrough is part of Premium
The statement and the examples above stay free. The full how-to-solve walkthrough, the cost notes in plain words and the interactive step-by-step visualizer unlock with a Premium plan.
See pricing