Kadene's algo in the all negative enteries

sir what if all enteries of an array for example : (-5,-23,-88,-45,-9,-1,-89,-45,-78) will this algo return -1 or not because -1 is the maximum sum of any subarray of this array

Yes you are correct…

means this is constrain for kadene,s algorithm

Kaden’s algo work for positive as well as negative number so it will return the min. Sum of subarray
In ur example -1 will be the ans.

sir but the explanation in the video doesn’t seams like that

Refer this


If u have any problem reply

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.

Is your doubt resolved ?

there is error in the code shown in video also in the code provided in the maximum circular sum subarray pdf here cs is updated to zero ,if it is negative .this line should come after comparison with max sum and update of max sum

if we think logically sir here in this code , maximum sum variable value will always get the value of current sum variable,and initial value of maximum sum is zero ,and cs gets negative then we make value of cs =0; that means ms cant receive negative value because it can receive value from cs and cs cant be negative. therefore if we have all elements in array are negative then according to the code taught in video cant give us never any negative value , our ans will be zero in that case acc to the code in video . but the answer is least negative value

@pankajsingh The code given in the lecture video of the course will not give correct answer when all array elements are negative. It will give 0 as output when all array elements are negative.
So to correct it, just consider a special case. If all array elements are negative the answer will simply be the least negative number. So by maintaining a check of least negative number, you can handle this case.

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.