Kadane algorihtm

what will be the output if the array contains only one or two negative number
arr []= [-1], arr[] = [-1,-2]
it return -1 , -3 or 0

okay means the number who is smaller should be return , -1 is greater than any other number negative number

@Vikaspal
you return the maximum negative number, viz -1 here, (don’t get confused, refer this reply only now).

@mahimahans111 means in our example
arr []= [-1], result = -1 only one subarray

, arr[] = [-1,-2] result = -1 two subarray the result for one subrray is -1 and for another subarray the result will -1+(-2) = -3 so -1 is > -3 so result is -1
Right ?

@mahimahans111


the kadane algo doesn’t work if all the number is negative it require at least one poistive number?

No @Vikaspal
you’ve return the maximum negative number in case all numbers are negative.
(You will find certain articles saying opposite things).

@mahimahans111 thanks I got the intiution.

1 Like

@Vikaspal
Can you mark the doubt as resolved, if it’s clear to you now

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.