How this output came as 22

please tell that which numbers from input had been added to get 22 as sum

@AjAy03 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:

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.

1 Like