Maximum Circular Subarray Sum
Maximum Circular Subarray Sum
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 again apply Kadane's Algorithm to calculate the maximum sum
subarray of this new inverted array.
But we should keep in mind the fact that the maximum sum of the inverted subarray is actually
the minimum sum subarray for the original array. So if we subtract the negative value of this
new sum from the cumulative sum of the original array we will get another candidate for the
answer and name it candidate2. Then compare both the candidates and return the larger
number.