Max sum submatrix in row

the code is not giving correct output for
-5 -4 -1
-3 2 4
2 5 8
but giving correct output for
1 1
1 1

where is the problem?

hello @dsdishu99
here u r accessing negative indices


when x=0 or y=0

what should it be instead?

see bottom right corner of required matrix will always be (n-1 ,m-1) because array is row and column wise sorted.
after getting suffix array.
simply use two loop
for(int i)
{
for(int j ){
check suffix[i][j] if it is greater than max then update ur max.
}
}

So I should define x=n-1 and y=m-1 instead of applying 2 for loops for them?
Rest of it keeping it same!

no,
just compare ur max with suffix[i][j]
suffix[i][j] gives u sum of summtrix whose top left corner is (i,j) and bottom right corner is (n-1,m-1)

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.