The negative numbers make us think "what should I do if on the way of collecting the sum I saw a negative number, should I collect it and continue or should I stop collecting right there?". Here is the answer, if after collecting the negative number your current sum is more than 0 you should keep collecting because you might get a better result (don't forget to update the maximum value of the final answer every time).
No comments:
Post a Comment