My code isnt workign could you point out what is wrong in my code?

this is the link to my code

please point out the wrong logic in my code by commenting
also it would be really helpful if you could suggest a more efficient way for solving this question with another code

you are considering simple subarrays
not circular subarray

you have to use kadane’s algorithm to solve this problem

Method 1 There can be two cases for the maximum sum:

  • Case 1: The elements that contribute to the maximum sum are arranged such that no wrapping is there. Examples: {-10, 2, -1, 5}, {-2, 4, -1, 4, -1}. In this case, Kadane’s algorithm will produce the result.
  • Case 2: The elements which contribute to the maximum sum are arranged such that wrapping is there. Examples: {10, -12, 11}, {12, -5, 4, -8, 11}. In this case, we change wrapping to non-wrapping. find out the sum of non-contributing elements and subtract this sum from the total sum. To find out the sum of non-contributions, invert the sign of each element and then run Kadane’s algorithm.
    Our array is like a ring and we have to eliminate the maximum continuous negative that implies maximum continuous positive in the inverted arrays. Finally, we compare the sum obtained in both cases and return the maximum of the two sums.

there are fixed steps to solve this using kadane’s algorithms see the Reference Code below

i understood the kadane’s algorithm part, but what is happening in the maxcircular sum function part?

i have commented the steps

first we find the answer using simple kadane’s algo
this is case 1 ,it doesn’t include circular sum

so to find circular ans as well for that we follow these steps

first invert sign of each element
then run kadane’s again and add this to total sum

now take max of both options