please explain me the max_wrap function in more detail used in maximum circular subarray sum
why we are changing the sign of the array
Wrapping function
First we find the maximum sum subarray using kadane’s algorithm, Now we want to find maximum sum of wrapping subarray. Every time we select a subarray from a circular array it divides the circular array into two parts a wrapping subarray and a non wrapping subarray. we select the non wrapping subarray since the sum of the entire circular array is constant and sum of wrapping and non wrappping sub array is equal to sum of circular subarray, In order to maximize the wrapping subarray we need to minimize non wrapping subarray but kadanes algorithm only finds maximum sum subarray so thats why we invert sign cuz this way it’ll find minimum sum subarray rather than maximum and we’ll subtract it from circular sum to get maximum wrapping subarray sum.
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.