Modifications in kadane's algo

what if all the elements in the array is negative?

hello @tishya_goyal
intialise ur maximum variable with value of any element of array ,it will work fine for every case

i didn’t understand…
if all the elements are negative we have to return single element or largest sum of negative elements…
could u plz explain it using eg. or plz provide me any source from where i can read it…

max=a[0]
run ur code of kadane and see the output
it will give correct output


is it correct?

image

u missed few lines of kadane ,also start i from 0.

okay…that means we have to print smallest negative no. of array if all no’s are negative

yeah , and kadane will handle on it own, u just need to intialise ur max with some value of array elements

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.