Why is my code not able to compile?
Explain the error in code
hey @goyalvivek
while(j != i)
{
if(j >= n and p == 0)
{
j = 0;
p++;
}
cout<<a[j] <<" ";
/*s += a[j];
if(s <0)
{
s = 0;
}
m = max(s, m);*/
j++;
}
Your this part of code is cause an error. i am not able to get the logic you have applied here.
i am trying to use kadanes algo but in circular way
sum elements from i to i-1
what according to you will be answer for this
1
6
1 2 5 -2 -3 5
try to think it like this
5 + 1 + 2 + 5 = 13 should be the ans i guess
i think my code should work fine but it shows an error, please resolve it
right, now implement it using the code i have provided you above.
your code shows ans as 5
check again, i have updated the link, have attached wrong code by mistake.
please provide the link again, unable to access the earlier one
i did a dry run myself and it works perfectly, please explain the working
read this
it’s a good editorial
c1=kadane(a,n); why have we done this? code works without it too
this is for greater value from linear kadane’s algo. We are doing this because if linear kadane’s answer is more than the circular kadane’s algo after changing sign, we can compare. See this for example:
5
-5 3 4 -2 1
in linear answer will be 7(3,4)
in circular, changed sign {5 -3 -4 2 -1} answer will be 6 (5, 2,-1)
Got it, thanks for ur help
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.