In the implementation if arr element like [-1,-2,-3,-4,-5,-----].
Then this implementions will print maxsum=0.But it should be -1.Should we make it any special case?
Maximum subarray sum (kadane's algorithm)
@gopi.jais0607
Hello Gopi,
you are correct kadane fails when all numbers are negative (according to wikipedia there should be alteast one positive number in array for kadane to work).
also it is easy to handle this case . just keep track of maximum in ur array .
if maxsum from kadane is 0 then print maximum otherwise print maxsum.
@aman212yadav Why can’t you just initialize maxSum with Integer minimum value instead of zero. Kadane’s algorithm will work on top of that.