Max circular sub array sum

take this example (1,-10,-10,21)
using kadane we get 21
now invert (-1,10,10,-21) use kadane 20
add 20+21=41
but the answer as u can see is 22
where am i wrong here?

@sktg99 Using Kadane you get 21.
Now for the Circular case:
Step1: Total sum of all elements( Taking Cumulative sum) : 1-10-10+21=2
Step 2: Invert all elements: -1,10,10,-21
Step 3: Apply Kadane on step 2. So answer is 10+10=20. But we had inverted the array elements, so it would be -20 for the non inverted array.
Step 4: Maximum Circular sum= Step 1 - Step 3 ie. 2- (-20) =22
Therefore the answer is max(21,22)=22

Hope this helps :slightly_smiling_face: