Max sub array kadane

getting one testcase wrong.

Save your code on ide.codingblocks.com and share its link.

Check now

is this line if(current<0){
current=0;
}
correct or it should be
if(current<arr[i]){
current=arr[i];
}

It is correct.
In kadane algo we check if current sum becomes negative, we reinitilize it to 0.
Has all your test case passed?

in other videos I have seen that they use this
current+=arr[i],
if(current<arr[i]){
current=arr[i];
}

Yes this may be the modified version of Kadane (where all negative numbers are also allowed)
So you can follow that approach.

currentsum=0 if negative aprroach is for both the cases if all are negative nums and mixuture?

The approach as i said (and the approach that was in your code) will fail when all numbers in the array are negative.
The other approach will handle all the cases.

When all array elements are negative, maximum subarray sum is simple the least negative number.(ie. highest among all the -ve numbers.)

is there a updated version of kadanes which handles all the cases?

But I have not included this case when all are -ve then also my all testcases are right why?

Refer the 3rd code from this article

Yes…in this question it will work.As all array elements will not be negative here.

similary we can find min subarray using kadane?

Yes

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.