Max Array Sum

  • + 51 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:

    • value @ 0
    • value @ 1

    from that point forward, the max of the next position is either:

    1. the current value at that position
    2. the max value found so far
    3. 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