Kadane's algorithm doubts

how to print the exact subarray with maximum sum using kadane’s algorithm?

@Subham2107 hey subham there is a code for print the exact subarray you can refer this.

1 Like

How to consider the case when all numbers in the array are negative?The maximum sum of subarray should be negative in that case and not 0 ,right?

@Subham2107 hey shubham you are right in this case you can refer this.

this code is not giving correct answers for some of the test cases.For eg
1
4
5 2 -3 4
answer should be 7,but code is showing 8.

@Subham2107 no it should be 8 by considering the subarray 5+2-3+4=8. how is it be 7 please can you please elaborate which application of kadane algo you are talking about

Ok sir.Got it…

Hey Shubham,
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.