if i give above input then your code"s output will be 0,but it should be -1 ,as it is max sum subarray
-1-2-3-4-5 as input
What is your question? I didn’t get it.
if i enter one test case:
-1 -2 -3 -4 -5 as input to find its maximum sum subarray
Answer is -1. It is the maximum subarray sum possible.
A subarray should have atleast one element. And all elements should be continuous.
yes,but according to Kadane’s algo output is 0!
Yes. You have to modify the algorithm a bit. It works fine if atleast one value is positive in the array.
Just add one statement to your code after the for loop -
if(maxsum==0)
maxsum = *max_element(arr.begin(),arr.end());
now ,i got it.Thank You sir.