KADANE'S Algorithm in negative numbers

How will can apply Kadane’s algorithm if all the numbers are negative in an array. In such case it will always give the maxSum as zero as we making the countSum equal to zero in case of negative sum of a subaray. How we can solve this problem?

You can first find maximum element in the array and see if its not negative and then run kadane, otherwise just print the maximum element.

1 Like

Thanks for your reply! Got it…