Skip to content

Conversation

@fish-404
Copy link

Considerate if a array is all of negative numbers, it shouldn't return 0 as maximun subarray sum

Considerate if a array is all of negative numbers, it shouldn't return 0 as maximun subarray sum
@64json
Copy link
Member

64json commented Nov 30, 2021

I think it is a correct behavior to return 0 for a negative array, since an empty array is also a subarray. Feel free to reopen it if you think otherwise.

@64json 64json closed this Nov 30, 2021
@fish-404
Copy link
Author

fish-404 commented Dec 2, 2021

Hi, I think it depends on wheter we admit a empty is a subarray.
I meet this problem in LeetCode (No. 53). And the test case shown they won't regard empty array as a subarray. If the test case is a negative array, it will return the max negative num.
I check reference in Wikipia and GeeksforGeeks, GeeksforGeeks doesn't admit a empty as a subarray. And Wikipia expian the algorithms history, disallow empty subarrays is a variant of the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants