Taking cs=0 when cs is negative

what if all the inputs that we have provided are negative and we want the sum that provides us the least negative answer, but according to this code we are gonna get 0 as our answer.

The condition for the Kadane’s Algorithm is that at least one element must be positive. If all elements are negative then the answer is simply the least negative number.

1 Like

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.