I don’t know what’s wrong with my code. Please suggest an explanation for this problem.
Maximum Circular Subarray Sum Problem With Code
Hey Ishwar!
Try to solve this problem with the help of Kadane’s algorithm.
There can be 2 cases in this question:
When max sum is given without wrapping:
Example: 1,-2,10,11,-1,20,-50
here 10,11,-1,20 will give the max sum, simple case : here kadane’s algo will work fine
case 2: Wrapping:
Example: -1 100 -10 17 3 4 -2 -2
here max sum will be given by 17,3,4,-2,-2,-1,100
wrapping is there, as we are starting at 17 then going on till -2,-2 and then going at -1,100 (as its a circular array so we can start from any point), here simple Kadane’s algo won’t work.
I have commented the hint in this code:
Please check I have tried it but its not working. Please help. Its correct but don’t know what’s the problem.
Check this code, I have debugged it.