Well, if we are trying to solve it when there are both positive and negative integers in the array, than DrPizza''s solution is entirely correct.
However, the intent in the problem statement looks like it means it *can* contain both positive and negative integers. However, if it''s truly "both" then my solution is completely unneccesary. But it was fun nonetheless .
Challenging programming question
quote:Original post by Flarelocke
The only case where it doesn't work is when there's an array of nothing but negatives, which falls outside the domain of the problem. Therefore, it works.
Of course it does. The array has n negative numbers and 0 positive ones.
In any case, the question is supposed to ask for the maximum segment sum; the list of questions is (allegedly) a list used by MS.
That said, I would be quite surprised to be asked such a question in an interview; the solution to such a problem is generally "look it up in a book".
[edited by - DrPizza on September 16, 2002 10:51:09 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement