not able to underatand the problem,pls give 3 eXamples with explainations
Maximum Circular Subarray Sum
Hey Shubham, in this problem you have to find the maximum sum subarray but the twist is you will consider array as a circular array here. Let’s understand it with some examples
input :
3
7
8 -8 9 -9 10 -11 12
9
2 1 -5 4 -3 1 -3 4 -1
9
-3 1 -3 3 -1 2 1 -5 4
So, here we have 3 arrays,
first with 7 elements 8 -8 9 -9 10 -11 12 , here you can see max sum will be 22 = 12 + 8 + (- 8) + 9 + (- 9) + 10.
So, here as we are assuming the array is circular hence, it will not have a start or end point. To take a subarray, we can consider the first element as the consecutive element of the last element.
second with 9 elements 2 1 -5 4 -3 1 -3 4 -1 it will have max sum 6 = 4 + (-1) + 2 + 1
third with 9 elements -3 1 -3 4 -1 2 1 -5 4 . it will have maxsum 6 = 4 + (-1) + 2 + 1
I hope its clear to you now that how we can take a circular subarray with max sum.