Maximum circular subarray summation

can u just plz give detailed explanation of the logic behind this.

two cases follow in this.

  1. no wrapping is there among the numbers that will produce maximum subarray sum
    kadane’s algo will work perfectly fine.
  2. wrapping exists in elements that will produce maximum subarray sum.
    we need to change wrapping-> non wrapping
    this can be done by
    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
    try to dry run the logic you will get to know the actual functionality.
1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.