Kadane's Algorithm

In Kadane’s Algo I have to update the current_sum to 0 if the current_sum < 0. What if all the elements in the array is negative? In that case the current_sum or the max_sum wil never be greater than 0.

Yes, the normal Kadane algorithm will not work when all numbers are negative. For such a case, the maximum subarray sum will simply be the least negative number.

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.