Suppose my array has elements -2 -3 -1 -2…The maximum subarray sum is -1(the least negative element is what I want to say). So does this count as max subarray sum?
Maxmimum Subarray Sum and negative numbers
So if I am solving a question, will it be OK if I use Kadane’s algorithm, if the input constraint is not mentioned(if the numbers of the test case array are negative, then the max sum would not be right)?
U can make little bit changes in it to consider negatives also
Initalize maxsum as INT_MIN
And in loop before checking for sum<0 add statement to check max
OK! Understood! Thanks!
1 Like