Kadane's algorithm

basically what if all elements of an array are negative ,then how can we get maximum sum as it takes each negative sum to be 0?

@J20APPPP0006
hello Navpreet,
initialise ur maximum variable to INT_MIN it will handle all negative case easily

but according to the algorithm whenever current sum encounters negative value we manipulates to a value of 0. so how will it store negative value(maximum sum)

we do that with maximum_running_sum and not with maximum variable .

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.