Maximum Circular Sum

What is wrong with my solution?
ProblemLink:
https://online.codingblocks.com/app/player/47935/content/33525/5302

Solution Link:

Hey @mohitsethia there were couple of mistakes in the code

  1. sum of the array (cs2 += a[i]) would come under loop where you turn each element negative not under the loop which provides you the maximum sum
  2. the output is maximum of cs1 or cs2 not the sum of cs1 and cs2
    Here is the link of rectified code:https://ide.codingblocks.com/s/171711
    Let me know if you still face some trouble.

I didn’t get you. I think you didn’t save the code after rectification, so there is no change I can see.

My bad, here is the new link:https://ide.codingblocks.com/s/172149

Hey @mohitsethia i hope i have solved your doubt if so, please mark the doubt as resolved.

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.

Please can you explain once why are we doing like this to calculate maximum sum. Can’t we just use the array elements twice, like in the sample input elements were 8 -8 9 -9 10 -11 12, we can take 8 -8 9 -9 10 -11 12 8 -8 9 -9 10 -11 12 and calculate the maximum sum

Yes it is possible to solve this question by taking each element twice but you have to make sure that your maximum window size doesnt exceed n which means you’ll have to write extra if conditions and all to make sure everything is working fine but in the “kadane algorithm” we can use the same piece of code to get the solution.