-
Max Subarray challenge
The solution to the Max Subarray challenge here: http://www.cprogramming.com/challenges/array_sum.html
does not work for an input of all negative integers.
For example
Code:
int y[] = {-9, -8, -7, -5, -1, -9};
put through the function should return -1. But the solution code returns 0.
-
No, -1 is correct if you don't allow 0 length sub arrays.
edit: Bleh misread your post. So I guess the question is if it allows 0 length sub arrays. Which I guess the solution allows. I guess the question should specify if an empty set is a valid solution.
-
In the problem page http://www.cprogramming.com/challenges/array_sum.html
the answer given is a 0 length sub array.
-
Yes, the solution is wrong. And there is some inconsistencies in the question. But I'm not sure exactly who we should tell.