can we print subarray which has max sum using kadane’s algo if yes then how?
Kadane's algo doubt(max subarray sum)
yes you can do so.
initialize start and end as 0 initially
while updating the max_so_far and max_end update the start and end indexes
int max_so_far = INT_MIN, max_end = 0,
start =0, end = 0, s=0;
for (int i=0; i< size; i++ )
{
max_end += a[i];
if (max_so_far < max_end)
{
max_so_far = max_end;
start = s; // starting point
end = i; // ending point
}
if (max_ending_here < 0)
{
max_ending_here = 0;
s = i + 1;
}
you will get start and end indexes and then you can print the subarray within that range