arrayscomplexitydynamic-programming
Keep the all-negative case in maximum subarray
Anonymous
For a non-empty array, the best subarray ending at the current value is either that value alone or the previous ending sum plus that value. Track the largest ending sum and the best sum seen overall. Start from the first element so an all-negative input doesn't accidentally produce zero. This scans once with constant extra space.
0