Maximum Circular Sum

How to solve this problem???

have you studied “kadane’s Algorithm” or not??
this question is solved using “kadane’s Algorithm”

if you don’t know “kadane’s algorithm” first learn the algorithm
and if you know algorithm then see…

Approach:

  • Case A: If The elements that contribute to the maximum sum are not arranged in cyclic order.
    Examples: {-8, 2, -1, 7}, max_sum=7
    {-2, 6, -1, 7, -2} max_sum =(6+(-1)+7)=12
    In this case, “kadane algorithm” solve our purpose.

  • Case B: If The elements which contribute to the maximum sum are arranged in cyclic order. Examples: {10, -12, 11}, {8 -8 9 -9 10 -11 12}. In this case, we change cyclic to non-cyclic. Let us see how.

contributing elements(cyclic) sum = total sum - non-contributing elements(non-cyclic) sum,

so find out the sum of non-contributing elements and subtract this sum from the total sum. To find out the sum of non-contributions, run Kadane’s algorithm.

Reference Code is:

https://ide.codingblocks.com/s/640836 This is my code vaibhav it is giving the right answer but it isn’t passing any test case…please help me here

when i am dry running your code my opt2 is coming -1 and total is 11 then how the hell it is coming 22… i am not able to get your code…i even wrote down on notebook

in your code at line no 28
c2=c2+kadane(a,n);
this is incorrect correct statement will be

c2=c2-kadane(a,n);

now it should work fine

I did the same thing still no test case is getting passed…please help saurabh

please explain me your code …the problem i am facing in your code is when i am dry running your code my opt2 is coming -1 and total is 11 then how the hell it is coming 22… i am not able to get your code…i even wrote down on notebook

learn it from here YouTube Link
well explained

but why isn’t any test case is passing even after doing the changes you asked me to do it

are i watched your video and got the solution but why isn’t test case getting solved??? it’s not passing any test case

i am checking your code
wait for some minutes

please do share the link of your rfernce code becuase the one you send it’s not openning and i have mentioned the complaint to support.

Modified Code

Your mistake
you have to print the ans of each testcase in separate line
hence use endl

sorry for that
you should mention this here i would send you again