Max circular subarray

not getting correct output

@guptashubham210a
what is the logic that u are using ??

I am finding total sum then - min sum subarray

i have got it correct but only testcase 0 incorrect idk why?

but the code u gave here is giving 2 output for 1 test case
and that too wrong

share code which passes 1 test case if u have it

then also its giving testcase error 0

5
-5 3 4 -2 1
ur code answer 6
required
7

but logic is correct na?

i know of the kadanes algo to solve this question
not able to figure out where ur code goes wrong

u can read the explanation here

but I have done that only first finded min subarray sum using kadanes and subtracted from total sum as written in this…

@guptashubham210a
You have implemented only half of the correct algorithm. There are two parts to it. Two cases.
For case 1 you run a normal kadane algo on it and store the result. Lets say the result is stored in some variable called ‘ans1’.
Now you run the code for case 2 which is the part that you have executed in your code. The result for that is ‘ans2’.
Your final answer is the max of these two
ans = max(ans1, ans2)

Consider this testcase
1
7
-5 -4 -1 3 -8 -6 -2

Your code gives 0 when the answer is clearly 3

what are the two cases?

@guptashubham210a

sir has mentioned the 2 cases in the explanation

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.