Kadene's Algorithm not working

I just watched the video for Kadene’s algorithm and decided to implement it. However, I am having a little problem with my code as the output is coming out not as expected.

After inputting values {-1, 0} it gives output as: 0.
but for values {-1,-1} it is still giving out output: 0.

I made sure that my code is correct and deleted y whole implementation and re-wrote it exactly as the mentor showed but it is still not working. Is this a compiler issue? I am confused.

hello @rahulrana1998

here each element is negative, the usual kadane implementation will not work here

u can modify its implementation a bit , to make it work for evry cases.

int max_so_far      = array[0];
int max_ending_here = 0;


for (int i = 0; i < size; i++)
{
    max_ending_here =max_ending_here + array[i];
    max_so_far      = max(max_ending_here, max_so_far);
    max_ending_here = max(max_ending_here, 0);

}

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.