For example, given
A = [1,51,3,1,100,199,3], maxSum = 51 + 1 + 199 = 251.
clearly max(oddIndexSum,evenIndexSum) does not
max(oddIndexSum,evenIndexSum)
find_max(int t, int n) { if(t>=n) return 0; int sum =0, max_sum =0; for(int i=t; i max_sum) max_sum = sum; } return max_sum; }
The above is a recursive solution, have not compiled it. It's fairly trivial to see the repetition and convert this to a DP. Will post that soon.