why do we need to invert the sign of array to find out the max circular sum
Why do we need to invert the sign of array
Basically for calculating the maximum-circular-sum, you have two options or two cases,
Case 1: The elements that contribute to the maximum sum are arranged such that no wrapping is there.
Case 2: The elements which contribute to the maximum sum are arranged such that wrapping is there. In this case, we change wrapping to non-wrapping. Wrapping of contributing elements implies non wrapping of non contributing elements, so find out the sum of non contributing elements and subtract this sum from the total sum. To find out the sum of non contributing, invert sign of each element and then run Kadane’s algorithm.
Our array is like a ring and we have to eliminate the maximum continuous negative that implies maximum continuous positive in the inverted arrays.
Finally we compare the sum obtained by both cases, and return the maximum of the two sums.
This is why we need to invert the sign of array… I hope you understood this…