Maximum Circular Sum

My code is working for test cases 1-5 but it is failing for test case 0, can you please check and tell me where I’m going wrong?

Here’s the code link: https://ide.codingblocks.com/s/620429

you have consider only one option
that if you consider elements circularly

what if you didn’t consider circularly
simply without circular move you get max ans

consider this input
5
-5 3 4 -2 1
if you move circularly you get 6
but simply you can get 7 (3+4)
so ans is 7

you also have to consider simple kadane’s algorithm

and then ans is max of both

check out modified code below

Modified code

I understood it now, but if we apply totalSum - minSum we do get the ans as 7 but only if we do it by ourself if I do it by code it surely fails which means we are not actually moving around in circular pattern if we look at code. Honestly I’m still so confused like how this method working, I watched so many youtube videos but still it’s not very clear to me.

Do you have some source to understand the subtracting miniumum from all array sum better? I want to understand how this method works properly

sorry i am not able to reply you

you can understand complete logic of this question
from here
really good explanation

I understood it now, Thanks a lot for providing the link!! :slight_smile:

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.