Find the contiguous subarray within an array (containing at least one number) which has the largest sum.
For example, given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [4,-1,2,1] has the largest sum = 6.
I am unable to solve this problem, but I would just like some hints.
It it said this can be solved using Dynamic Programming, but I am struggling to see a connection.
Would the DP connection be taking the sum of the whole array?
A[n]
. Now build another arrayB[n]
such thatB[k]
contains the contiguous subarray inA
with the biggest sum starting exactly atA[k]
. And, as it's typical in DP, build It from the end --B[n]
is obviously just one-element arrayA[n]
. Knowing that, can you determineB[n-1]
?... – avysk