Maximum circular sum

why my code is not giving the write output even though i tried to Dry run it during dry run it showiing the correct output(in the test cases given in question )https://ide.codingblocks.com/s/431281

You need to first use kadane’s to check. And then the circular sum one. See this https://ide.codingblocks.com/s/431302

1 Like

https://ide.codingblocks.com/s/431281 I changed my code test case’s output is correct this time but it is not accepting why?

You are missing the kadane’s part.

First you need to solve using normal Kadane’s algorithm. Call it as S1.

After that make all elements negative, and then find maximal possible sum using kadane. Add this to total sum of the array. Call this S2. ( You are only calculating this in your code I think).

Now your answer is the maximum of S1 and S2. Please see the code I shared.

are we doing s1 because there could be a possibility that the straight array can have the maximum sum right? and that case is not being covered by s2

Yes, S2 doesn’t cover that case.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.