this is the link to my code
please point out the wrong logic in my code by commenting
also it would be really helpful if you could suggest a more efficient way for solving this question with another code
this is the link to my code
please point out the wrong logic in my code by commenting
also it would be really helpful if you could suggest a more efficient way for solving this question with another code
you are considering simple subarrays
not circular subarray
you have to use kadane’s algorithm to solve this problem
Method 1 There can be two cases for the maximum sum:
there are fixed steps to solve this using kadane’s algorithms see the Reference Code below
i understood the kadane’s algorithm part, but what is happening in the maxcircular sum function part?
i have commented the steps
first we find the answer using simple kadane’s algo
this is case 1 ,it doesn’t include circular sum
so to find circular ans as well for that we follow these steps
first invert sign of each element
then run kadane’s again and add this to total sum
now take max of both options