One of my test case is not working

try this input n=3
1
2
3
didn’t get the expected output

@S18ML0036
hello himanshu,
approach is correct.u need to handle one corner case when i=0;
in that case sum=cusum[j] only .

n is 3 here and 1 2 3 is the input in array

cummulative sum array will look like

1 3 6
now for i=0 we will run j from j->0 to j=2

and because i=0 we will not subtract cumsum[i-1] .

so cumsum[2]=6 will give us maximum sum in the array.

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.