I tried to solve Special sums problem, but I am not able to figure out what exactly I am supposed to do in that problem.
In your sum, you have i and j
if i<=j, your sum would be a[i]+b[i+1]+b[i+2]…b[j-1]+a[j]
if i>j, your sum is equal to a[i]+b[i+1]+b[i+2]+b[N-1]+b[0]+b[1]…b[j-1]+a[j]
you’re meant to select i and j, such that the sum you achieve is the biggest possible sum(which you then output)
U have to just output the maximum special segment sum.
We can easily do this with prefix and suffix sums.
lets consider the two cases differently:
case 1: st<=end
So iterate from i=1 to N,lets store at val[i] the maximum possible sum ending at i,so val[i]=a[i]+summation(b[j(not starting with it)])+a[j]; (here j<=i )
So indirectly we have to maximzse summation(b[j])+a[j],so while iterating we could just store maximum value of suffb[i+1]+a[i] (suffb[i+1] denote the suffix sum starting with i+1)
so val[i]=a[i]+max-suffb[i]
similarly u can handle second case.