Test case going wrong but sample input answer is correct

https://ide.codingblocks.com/s/138683 I am unable to debug my code

Hello Tanjul,
Your code works for maximum subarray and sometimes for circular subarray. In the sample test case the elements taken are (12 8 -8 9 -9 10) starting from the last element 12.

Normal max subarray problem uses a simple Kadane’s algorithm.

Circular array uses a modified kadane Algorithm. In that you have to first calculate the max subarray sum in the given array. Now calculate sum of all elements in array and then multiply every element by -1 and then find max subarray sum again and then subtract that from the sum of all elements. Now you will have 2 values, one value from the normal maximum subarray sum and another from the difference of array sum and maximum subarray sum after we multiply every element by -1. The answer will be maximum of these 2 elements.

You can use the below test case for reference:
1
5
12 -6 4 -9 10

Correct answer will be 22.
Your code will give output 12.