Max circular sum

satisfying sample inputs but not passing the test case

Kanishka, plz change your kadane function, as kadane function says that if cumulative sum at any point is less than 0, then cumulative sum becomes 0, and if it is greater than maximum sum, then max_sum=cumulative sum , apply this logic for your function,

2nd error, in your code is in line 44, where you will calculate sum1 as you calculated for a[i], and then you find out overall value, and then maximum of two values will be the result

Mam but for all negative entries kadane’s algo will not work that way. Can I ignore that case?

In Kadane algo, it is mandatory to have atleast one positive value, you cannot have all elements to be negative, so the approach which I have told will work well even if elements will be negative.

1 Like


the code is still not working

Use endl at line no 98, the code will work