I dont know to use kadane in negative input
I dont know to use kadane in negative input
hey @anmolaggarwal.432
kadane with negative inputs is quite similar to kadane with positive input
Initialize:
max_so_far = INT_MIN
max_ending_here = 0
Loop for each element of the array
(a) max_ending_here = max_ending_here + a[i]
(b) if(max_so_far < max_ending_here)
max_so_far = max_ending_here
© if(max_ending_here < 0)
max_ending_here = 0 // we simply make max_ending_here = 0 so we don’t
//take negative as answer instead answer should be 0 as 0>-ve values
return max_so_far
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.