What if the all elements are less than Zero
Negative number
Hey @tddewan2 you got it right, actually in video kandane’s algorithm was being treated by using 0. Which is fine but not appropriate. that why u can write kadane algo as :
int max_subarray_sum(int a[], int n){
int current_max = 0;
int max_so_far = INT_MIN;
for(int i=0; i<n; i++){
… current_max = max(current_max + a[i], a[i]);
… max_so_far = max(current_max, max_so_far);
}
return max_so_far;
}
Hope this would help you in understanding this algo in a better way 