mgechev / javascript-algorithms

💻 JavaScript implementations of computer science algorithms
https://mgechev.github.io/javascript-algorithms/
MIT License
7.83k stars 1.27k forks source link

Maximum subarray O(n) solution incorrect #137

Closed emyarod closed 6 years ago

emyarod commented 6 years ago

The current implementation will fail the following tests:

maxSubarray([]); // returns 0, should return `undefined`
maxSubarray([-42]); // returns 0, should return 42
maxSubArray([-10, -1, -2, -3, -1]); // returns 0, should return -1