It will give 0 output even if all numbers are negative
If all numbers are negative
According to Wikipedia, Kadane’s Algorithm requires at least one positive number , so your all negative array is invalid input. When all elements are negative , the maximum subarray is the empty subarray, which has sum 0.
@girishgargcool
I have modified the code to work for all negative case. How should I post it?
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.