Error running test cases

https://hack.codingblocks.com/app/contests/346/p/1040
I tried this question but can’t understand why it is not accepting all the test cases, I ran it for 2 2
-1 -1 -1 -1 it was fine but the given test cases won’t work. What can be wrong with this?

Please share your code

What is your approach? I don’t see you calculating the maximum sum submatrix anywhere in your code.
Also for the test case 2 2 -1 -1 -1 -1 ,your code is giving -16 as output which is incorrect.

Oh, yes. I’m calculating the sum not the max sum and can you please tell me how can we actually take the case for negative elements?

Idea is to extend Kadane’s algorithm, take a look at this blog for further insight https://www.tutorialspoint.com/Maximum-sum-rectangle-in-a-2D-matrix

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.

1 Like