Whats wrong in my code?

code for kadane is not correct as well as the approach to circular sum is wrong

check out this code

int maxCircularSum(int a[], int n)  
{  
    // Case 1: get the maximum sum using standard kadane'  
    // s algorithm  
    int max_kadane = kadane(a, n);  
      
    // Case 2: Now find the maximum sum that includes  
    // corner elements.  
    int max_wrap = 0, i;  
    for (i = 0; i < n; i++)  
    {  
            max_wrap += a[i]; // Calculate array-sum  
            a[i] = -a[i]; // invert the array (change sign)  
    }  
      
    // max sum with corner elements will be:  
    // array-sum - (-max subarray sum of inverted array)  
    max_wrap = max_wrap + kadane(a, n);  
      
    // The maximum circular sum will be maximum of two sums  
    return (max_wrap > max_kadane)? max_wrap: max_kadane;  
}  
  
// Standard Kadane's algorithm to find maximum subarray sum  
// See https://www.geeksforgeeks.org/archives/576 for details  
int kadane(int a[], int n)  
{  
    int max_so_far = 0, max_ending_here = 0;  
    int i;  
    for (i = 0; i < n; i++)  
    {  
        max_ending_here = max_ending_here + a[i];  
        if (max_ending_here < 0)  
            max_ending_here = 0;  
        if (max_so_far < max_ending_here)  
            max_so_far = max_ending_here;  
    }  
    return max_so_far;  
}  

a[i] = -a[i]; // invert the array (change sign)

max_wrap = max_wrap + kadane(a, n);

Can you please explain the above two lines why we did this?

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. Let us see how. Wrapping of contributing elements implies non wrapping of non contributing elements, so find out the sum of non contributing elements and subtract this sum from the total sum. To find out the sum of non contributing, invert 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.

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.