Circular subarrays sum

I trying to do brute force kind of solution to generate the consective subarray in circular form.
But from my approach, if j ==n then it will give all the elements which less than the i index pos , but i need one elements at a time so for the consective form. if i==2 then my logic is not going to work.
like i =2 ; and the array elements suppose 10,20,-30,10,20
-30
-30 10 20
-30 10 20 10 20 — It will gives all the elements but i need
only first 10 and then 20

Can you more elaborate your problem by writing the sample output you want in your code.
I am not able to understand your problem.

I am trying to generate all the subarray in circular manner. If I am able to generate the all the subarrays then it easy to sum-up? The problem I am facing with my code that it will correctly generate the elements for the two loops means for the two index value. But my logic is fails after the two index value.

Firstly think in a way if this problem is not circular then you find the maximum sum subarray by running two loops. No then TLE will come. But that problem can be solved in O(n) by kadane algo. So trying to put in this question kadane algo also.
Now you put Kadane algo in this also. But your code will give WA in many cases. You dont handle many test cases.

HINT - In this problem, there can be two cases i.e. either the subarray having maximum sum is
obtained in a circular fashion or the subarray having maximum sum is obtained in a non-
circular fashion.
The non-circular maximum sum subarray can be obtained directly by Kadane’s Algorithm.
But the subarray with circular fashion cannot be solved by Kadane’s algorithm.

So to solve this problem we will first calculate the maximum sum subarray using Kadane’s
Algorithm and store it in a variable, say candidate1. Then we will invert the sign of every
element of the array and think further this .

Test cases not able to pass ?

Link is not opening.
You solution is correct. Only put endl at last.
Now problem is resolved.

1 Like

I think you have posted something else by mistake.

1 Like

yes, so sorry for that the question is solved already. thanks so much