Skip to content

Improve maximum subarray for negative array #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Improve maximum subarray for negative array #31

wants to merge 1 commit into from

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
2 participants