Oct-29-2021, 06:25 PM
(Oct-29-2021, 05:59 PM)deanhystad Wrote: There is an error in my code in that it starts with the assumption that the max sum will be greater than 0. It would be better if it initialized maxsum to [array[0], start, start]. That allows it to work for the case were all numbers in the list are negative. The correct answer for [-1, -2, -3, -4] is [-1, -0, 0] for my code.
I'm not sure how to go about fixing Griboullis' code. The problem is that with all negative numbers, sv and min(mv, sv) are always the same, so best = max(best, 0). Starting with max = array[0] does not fix the problem.
That's why I asked the question.
Still, I'm checking my solution for larger arrays,
will publish it when i'm sure.
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.