something with memory input?
No testcase passed whereas it is accepting custom input
why did you append the array twice? this should not be done.
for eg. the array is -1 3 4 5 6, then your code will give ans as 35, while the expected answer is 18.
you need to take circular sum in the consideration, but appending array twice is not the way for it.
how to do it?
step1. run kadane’s algo in the array, store ans in x.
step2. for every index i, sum up the max prefix sum to i and max suffix sum from i+1.
get the max of all, and store it in y.
for eg. the array is 4 5 -3 2 -8 9 -7 9… then say i = 3,
max prefix sum is 9(5 +4), max suffix sum is 11(9-7+9). their sum is 20. you can see that this is one possible circular sum. you need to do it for every index i and compute max among all these values and store this in y.
step3. return max(x,y)
thanks
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.