We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
To address with DP, work through the array, keeping track of the max at each position until you get to the last value of the array. You should start with the base cases defined before iterating through the remainder of the array.
max @ position 0: value @ 0
max @ position 1: either:
value @ 0
value @ 1
from that point forward, the max of the next position is either:
the current value at that position
the max value found so far
the max value from 2 positions back plus the current value
keep track of the max at each position until you get to the last position of the array
Max Array Sum
You are viewing a single comment's thread. Return to all comments →
To address with DP, work through the array, keeping track of the max at each position until you get to the last value of the array. You should start with the base cases defined before iterating through the remainder of the array.
max @ position 0: value @ 0
max @ position 1: either:
from that point forward, the max of the next position is either:
keep track of the max at each position until you get to the last position of the array